Hello Jordan, You can register services in the mocked Sling context:
@Rule public final SlingContext slingContext = new SlingContext(ResourceResolverType.RESOURCERESOLVER_MOCK); [...] slingContext.registerService(ResourceResolverFactory.class, new MockResourceResolverFactory()); Thus they will be injected when your tests run. Regards, Guillaume On Thu, Oct 20, 2016 at 5:37 PM, Shurmer, Jordan < [email protected]> wrote: > Hello, > > I've got an OSGi component that I'm writing unit tests for using > sling-mock. The component uses the @Reference annotation to inject a > resourceResolverFactory which it then uses to call > getServiceResourceResolver(). I'm wondering if there's a way to set up the > mock SlingContext so that this factory is properly injected when running > the unit tests. > > Right now I am defining my own bindResolverFactory method and passing in a > mock factory, but I am hoping that sling-mock or osgi-mock provides a way > for this to work ootb. > > Any suggestions? > > Thanks, > > Jordan Shurmer | Software Engineer | Scripps Lifestyle Studios > > 9721 Sherrill Blvd, Knoxville TN 37932 > Office: 865-560-4887 > [email protected]<mailto:[email protected]> > > SCRIPPS NETWORKS INTERACTIVE | the Leader in Lifestyle Media | > scrippsnetworksinteractive.com > HGTV | Food Network | Travel Channel | DIY Network | Cooking Channel | > Great American Country | TVN | Fine Living | Asian Food Channel > >
