My service class has a reference object of org.apache.sling.api.auth.Authenticator;
While I'm trying to implement a test class I'm getting the below error message for Authenticator.
org.apache.sling.testing.mock.osgi.ReferenceViolationException: Unable to inject mandatory reference 'authenticator' for class MyService
I have tried to create a mock object of Authenticator and registering it but the issue is still there. Can you please help me with this.
@Mock
Authenticator authenticator;
@BeforeEach
void setup(){
context.registerService(Authenticator.class, authenticator);
context.registerInjectActivateService(new MyServiceImpl(), "title", "My Service");
}
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @sravs , Can you try making the authenticator reference optional in your Service class.
@Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL)
private volatile Authenticator authenticator;
Thanks,
Krishna
Hi @sravs , Can you try making the authenticator reference optional in your Service class.
@Reference(policy = ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.OPTIONAL)
private volatile Authenticator authenticator;
Thanks,
Krishna