AEM Mockito junit testing for multifield | Community
Skip to main content
August 2, 2022
Solved

AEM Mockito junit testing for multifield

  • August 2, 2022
  • 3 replies
  • 2089 views

 

 

Hi All,
i have  written a multifield in if else statement now,
I need to write JUnits for that Method (getMltifeildlist()) help me with the Testing code for this method 

 

 

 

 

 

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

3 replies

Jagadeesh_Prakash
Community Advisor
Community Advisor
August 3, 2022

@harido you can write this as below

 

@BeforeEach
void setUp() throws Exception {
List<LinkComponentImpl> linkcomponentimpl = new ArrayList<>();

linkComponentimplClass = new LinkComponentImpl();
}

/**
* Test.
*/
@Test
void test() {
Assert.assertNotNull(linkComponentimplClass.getMultifieldlist());
}
Nandheswara
August 3, 2022
Use this code for Example
Main Class: @Override public List<String> getBooks() { if (books != null) { return new ArrayList<String>(books); } else { return Collections.emptyList(); } } Test Class: private final AemContext aemContext=new AemContext(); private Author author; @Test void getBooks() { aemContext.currentResource("/component/author"); author=aemContext.request().adaptTo(Author.class); assertEquals(4,author.getBooks().size()); assertEquals("JAVA",author.getBooks().get(0)); assertEquals("DS",author.getBooks().get(2)); }