Get reference to (Mock)ResourceResolverFactory
<p>I have a Sling model class containing a reference to a service of mine:</p>

<pre><code>@OSGiService
PlanService planService;
</code></pre>

<p>This service has a reference to ResourceResolverFactory, to get a ResourceResolver with the "admin user":</p>

<pre><code>@Reference
private ResourceResolverFactory resolverFactory;
</code></pre>

<p>I'm writing a unit test to test adaptTo on my model class. I'm trying to inject the reference to PlanService like this:</p>

<pre><code>@Rule
public final OsgiContext osgiContext = new OsgiContext();

osgiContext.registerInjectActivateService(new PlanServiceImpl());
</code></pre>

<p>But I don't know how to inject the reference to the ResourceResolverFactory.</p>

<p>I've tried like this:</p>

<pre><code>osgiContext.registerInjectActivateService(new MockResourceResolverFactory());
</code></pre>

<p>But I get this error: </p>

<pre><code>org.apache.sling.testing.mock.osgi.NoScrMetadataException: No OSGi SCR metadata found in classpath at OSGI-INF/org.apache.sling.testing.resourceresolver.MockResourceResolverFactory.xml
</code></pre>

<p>I couldn't find in the documentation and among all the mocking options available how to inject this service and get the reference automatically. Any help would be very helpful, thank you!</p>

<p>EDIT:
Thanks to Jérémie's answer, the ResourceResolverFactory is injected in the PlanService. However, I'm now facing this issue:</p>

<pre><code>[main] WARN org.apache.sling.models.impl.ModelAdapterFactory - Required properties [c.r.o.c.s.j.PlanService c.r.o.c.m.Plan.planService] on model class class c.r.o.c.m.Plan were not able to be injected.
</code></pre>

<p>I've tried to use the same line than for the ResourceResolverFactory:</p>

<pre><code>osgiContext.registerService(PlanService.class, new PlanServiceImpl());
</code></pre>

<p>And also to add</p>

<pre><code>MockModelAdapterFactory mockModelAdapterFactory = new MockModelAdapterFactory();
     mockModelAdapterFactory.addModelsForPackage("c.r.o.c.m");

osgiContext.registerService(ModelAdapterFactory.class, mockModelAdapterFactory);
</code></pre>

<p>But it's still the same problem...</p>

<p>EDIT 2: registering it with SlingContext instead of OsgiContext fixed the issue:</p>

<pre><code>@Rule
public final SlingContext slingContext = new SlingContext(ResourceResolverType.RESOURCERESOLVER_MOCK);

@Mock
PlanService planServiceMock;

slingContext.registerService(PlanService.class, planServiceMock);
</code></pre>