Unable to fetch Resource from AemContext : Mockito | Community
Skip to main content
Level 3
September 22, 2017
Solved

Unable to fetch Resource from AemContext : Mockito

  • September 22, 2017
  • 1 reply
  • 2779 views

Hi,

I am new to Mockito. I am trying to write test case for one of the model class.

Here I am using AemContext (io.wcm.testing.mock.aem.junit.AemContext) for initializing the resourceResolver finally fetching the resource.

I am able to get the resource resolver object from AemContext, but then unable to create a test resource using the below code.

private ResourceResolver resResolver;

@Rule

public final AemContext context = new AemContext(ResourceResolverType.RESOURCERESOLVER_MOCK);

resResolver = context.resourceResolver(); //output : org.apache.sling.testing.resourceresolver.MockResourceResolver@4923ab24

resResolver.create(resResolver.getResource("/tmp"), "testpage", Collections.<String, Object> emptyMap()); // throws null pointer exception.

Can someone please guide me how to create resource for unit test cases.

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 smacdonald2008

See this GEMS session and PDF - it touches on this subject -- From Unit Testing to Integration Test of an AEM Application

1 reply

smacdonald2008
smacdonald2008Accepted solution
Level 10
September 22, 2017

See this GEMS session and PDF - it touches on this subject -- From Unit Testing to Integration Test of an AEM Application

Level 2
August 31, 2020
Link is broken. Can you Please update this link.