Mocked Accordion Object returning null in CustomImpl Class - JUnit | Community
Skip to main content
Rohan_Garg
New Participant
November 2, 2022
Solved

Mocked Accordion Object returning null in CustomImpl Class - JUnit

  • November 2, 2022
  • 1 reply
  • 877 views

Hi AEM Community,

I have a strange issue when writing a JUnit for my Test class.

This is my custom impl class's code snippet which is being tested -

 

1. There is an object of Accordion interface

 

2. We are creating a custom getData method to create a custom analytics layer. As seen below a resource object is created from SlingHttpServletRequest adaptable interface.

The accordion object is used to inherit features from core component's data layer while resource object is used to get JCR data.

 

This is working fine when being called upon by the Accordion component in a page.

 

However, when running the same method via Test class as shown below - the accordion object is being returned as null even though it has been mocked!

 

The mocked accordion object is being created successfully in test class but renders itself as null in impl class.

Is there something amiss with mocking the below object ?

 

 

@arunpatidar, @kautuk_sahni, @mohit_kbansal, @b_sravan, @vijayalakshmi_s 

 

Thanks,

Rohan Garg

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Rohan_Garg

@arunpatidar  - Thanks for the link. My scenario differs slightly in below way -

 

I have 1 custom interface CustomAccordion which is not extending Accordion.

 

The implementation class for this is using the delegation pattern.

 

Observations

1. defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL is already present

2. Use one more adaptable to adapt Core Accordion Component not working. Its gives build error.

1 reply

arunpatidar
New Participant
November 2, 2022
Rohan_Garg
Rohan_GargAuthorAccepted solution
New Participant
November 2, 2022

@arunpatidar  - Thanks for the link. My scenario differs slightly in below way -

 

I have 1 custom interface CustomAccordion which is not extending Accordion.

 

The implementation class for this is using the delegation pattern.

 

Observations

1. defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL is already present

2. Use one more adaptable to adapt Core Accordion Component not working. Its gives build error.