Unable to inject mandatory reference in aem unit testing.
Hi,
I followed this AEM tutorial https://experienceleague.adobe.com/docs/experience-manager-learn/cloud-service/developing/advanced/service-users.html?lang=en
to set up a service class that loads once service user object is available.
@Component(
reference = {
@Reference(
name = wknd-examples-statistics,
service = ServiceUserMapped.class,
target = "(subServiceName=wknd-examples-statistics)"
)
}
)
public class ContentStatisticsImpl implements ContentStatistics {
My service works fine. The issue is when I am unit testing.
I get this error while unit testing:
org.apache.sling.testing.mock.osgi.ReferenceViolationException: Unable to inject mandatory reference 'wknd-examples-statistics' (org.apache.sling.serviceusermapping.ServiceUserMapped) for class com.adobe.aem.wknd.examples.core.statistics.impl.ContentStatisticsImpl
: no matching services were found. bundleContext=org.apache.sling.testing.mock.osgi.MockBundleContext@298f7b0a.
Error occurs when I inject the service as below:
context.registerInjectActivateService(newContentStatisticsImpl());
How do i mock @3214626. Please help

