hello robert.

the SCR metadata is currently only found if the class name matches exactly. not 
sure if we should change the default behavior of osgi mocks here as this should 
be the same in a real OSGi behavior (like automatically looking up the parents).

adding an explicit method to the helper methods 
org.apache.sling.testing.mock.osgi.MockOsgi which allows to pass in a reference 
to alternative set of SCR metadata for injecting the dependencies should do no 
harm.

alternatively a mockito spy wrapper may help? but probably this leads to the 
same problem.

stefan


>-----Original Message-----
>From: Robert Munteanu [mailto:[email protected]]
>Sent: Wednesday, January 29, 2020 11:50 AM
>To: [email protected]
>Subject: [mocks] Injecting references for a class with no SCR metadata?
>
>Hi,
>
>I am working in the following (admittedly exotic) scenario:
>
>1. An OSGi component with a number of dependencies
>2. A test that runs on a subclass of that method, overriding a method
>that I want to stub out locally
>
>I want to register the component and have the OSGi mocks library inject
>depedencies for references, maybe based on the SCR metadata of the
>parent class? I could not find anything in the API for that.
>
>Alternatively, I could whip up a patch that checks if the the argument
>to registerInjectActivateService is an instance of an anonymous class
>and walks up the inheritance chain until the first non-anonymous class
>is found and uses that for SCR metadata.
>
>Thoughts?
>
>Thanks,
>Robert
>

Reply via email to