the first variant should work if SCR metadata are present in the classpath.
did you test this by running the unit tests on the command line, or within an 
IDE?
if you use eclipse make sure to use m2e and make sure the maven scr plugin gets 
executed as well before running the test (e.g. by clean/rebuild the project).

the latest (not-yet-relased) version of osgi-mock implements a better error 
handling when the SCR metadata is not present [1]

some of this hints are documented here: [2]. perhaps this could be more 
prominent.

stefan

[1] https://issues.apache.org/jira/browse/SLING-4165
[2] 
http://sling.apache.org/documentation/development/osgi-mock.html#activation-and-dependency-injection


>-----Original Message-----
>From: Robert Munteanu [mailto:[email protected]]
>Sent: Tuesday, November 25, 2014 3:39 PM
>To: [email protected]
>Subject: Sling Mocks: registering AdapterFactory service
>
>Hi,
>
>I'm following the documentation at [1] to register a new adapter
>factory service. I'm using the SlingContext @Rule for this.
>
>What I see is that the short form does not work
>
>    context.registerService(new MyAdapterFactory());
>
>However, the long form works
>
>    context.registerService(AdapterFactory.class, new MyAdapterFactory());
>
>I'm not sure whether this is intended ( and therefore the docs should
>be adjusted ) or a bug ( and therefore the code should be fixed ).
>
>Thoughts?
>
>Robert
>
>
>[1]: http://sling.apache.org/documentation/development/sling-
>mock.html#adapter-factories

Reply via email to