Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Mocked Accordion Object returning null in CustomImpl Class - JUnit


Level 8

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 ?

Rohan_Garg_3-1667371574679.png  Rohan_Garg_4-1667371594614.png


@arunpatidar, @kautuk_sahni, @Mohit_KBansal, @B_Sravan, @Vijayalakshmi_S 



Rohan Garg

2 Replies


Level 8

@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.




1. defaultInjectionStrategy=DefaultInjectionStrategy.OPTIONAL is already present

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