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

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list
SOLVED

AEM Mockito junit testing for multifield

Avatar

Level 3

 

 

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 

 

 

 

 

 

Screenshot (201).png

1 Accepted Solution

Avatar

Correct answer by
Community Advisor
3 Replies

Avatar

Community Advisor

@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());
}

Avatar

Level 4
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)); }

Avatar

Correct answer by
Community Advisor