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


AEM Mockito junit testing for multifield


Level 2



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


Correct answer by
Community Advisor
3 Replies


Level 6

@HariDo you can write this as below


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

linkComponentimplClass = new LinkComponentImpl();

* Test.
void test() {


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


Correct answer by
Community Advisor