Leiste mit Community-Erfolgen erweitern.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

Diese Konversation wurde aufgrund von Inaktivität geschlossen. Bitte erstellen Sie einen neuen Post.

GELÖST

Junit for Optional.map()

Avatar

Level 7

I want to write Junit for 

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

.map(Page::getTemplate)

But I am unable to mock these.

1 Akzeptierte Lösung

Avatar

Korrekte Antwort von
Community Advisor and Adobe Champion

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

Lösung in ursprünglichem Beitrag anzeigen

1 Antwort

Avatar

Korrekte Antwort von
Community Advisor and Adobe Champion

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