AEM Mockito Junit testing for nested dailog box or multifield | Community
Skip to main content
Level 2
June 7, 2022

AEM Mockito Junit testing for nested dailog box or multifield

  • June 7, 2022
  • 1 reply
  • 2163 views

I am new to implement AEM Mockito testing and want to write junit test cases for nested dailog box for an example We have one model class "AccordionListModel" which contain the list of "AccordionModel"

While writing Junit not getting model class reference (AccordionListModel.java) via adaptTo method

Below are the attached files for reference:

 

-AccordionListModel.java

 

 

-AccordionModel.java

 

- AccordionListModel.json

AccordionListModelTest.java

 

 

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

1 reply

sthakur-1Author
Level 2
June 7, 2022

Hi Arun,

scenerio is different in my case I am using adaptTo()  method to create a model object which is not working if we have nested dailog box.

Below is my Test class code snnipet. adaptTo method throwing null pointer exception if model class has 

nested implemention.

class AccordionListModelTest {

public final AemContext ctx = new AemContext();

public AccordionListModel accordionListModel;

@BeforeEach
void setUp() throws Exception {
ctx.addModelsForClasses(AccordionListModel.class);
ctx.load().json("/com/corp/core/models/components/content/utilities/AccordionListModel.json", "/content");
}

@Test
void getTitle(){
ctx.currentResource("/content/AccordionList");
accordionListModel = ctx.request().adaptTo(AccordionListModel.class); // Not able to get the reference of AccordionListModel via adaptTo, getting null pointer exception
String expected = "hello";
String actual = accordionListModel.getTitle();
assertEquals(expected, actual);
}

}

 

arunpatidar
Community Advisor
Community Advisor
June 7, 2022