Given code:
public class TestExample {
@Rule
SlingContext slingContext = new SlingContext(ResourceResolverType.JCR_MOCK);
@Test
public void test() {
ResourceResolverFactory rrf = slingContext.getService(ResourceResolverFactory.class);
}
}
Gives me:
org.apache.sling.resourceresolver.impl.ResourceResolverFactoryActivator$1 cannot be cast to org.apache.sling.api.resource.ResourceResolverFactory
java.lang.ClassCastException
at example(ExampleTest.java:21)
Do I have to use slingContext.resourceResolver()
method? It is not flexible as I want, because of existing only ResourceResolver
instance at once (and it is closed on tearDown
which my class is doing by itself). Can I avoid this problem somehow?
The following code works for me
using the following dependencies
What versions of Sling mocks are you using?