Junit for Optional.map() | Community
Skip to main content
Level 6
February 13, 2023
Solved

Junit for Optional.map()

  • February 13, 2023
  • 1 reply
  • 699 views

I want to write Junit for 

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

.map(Page::getTemplate)

But I am unable to mock these.

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

@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");

1 reply

BrianKasingli
Community Advisor and Adobe Champion
BrianKasingliCommunity Advisor and Adobe ChampionAccepted solution
Community Advisor and Adobe Champion
February 15, 2023

@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");