Expand my Community achievements bar.

SOLVED

Junit for Optional.map()

Avatar

Level 6

I want to write Junit for 

Optional.map(pageResource -> pageResource.adaptTo(Page.class))

.map(Page::getTemplate)

But I am unable to mock these.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

@Shaheena_Sheikh , very simple, you would need to add mock resources in the AEMContext. In particular you would want to create pages like:

context.pageManager().create("/content/sample/page1", "page1",
        "/apps/sample/templates/homepage", "page1");

And you would want to pass in resolver.resolve("/content/sample/page1");

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

@Shaheena_Sheikh , very simple, you would need to add mock resources in the AEMContext. In particular you would want to create pages like:

context.pageManager().create("/content/sample/page1", "page1",
        "/apps/sample/templates/homepage", "page1");

And you would want to pass in resolver.resolve("/content/sample/page1");