Hello, Thank you! I just ran across this in the docs as well - not sure how I missed it.
-----Original Message----- From: Guillaume Lucazeau [mailto:[email protected]] Sent: Thursday, October 20, 2016 11:56 AM To: [email protected] Subject: Re: x SCR Annotations and sling-mock to get resourceResolverFactory 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 > >
