Mocking JobManager in junit unit TEst
Hi everybody,
Any help will be appreciated.
i am trying to create a unit test for myCustomService. This service has a reference to a JobManager. I didn't find any precise documentation to do that.
Here what i do :
@ExtendsWith({AemContextExtension.class,MockitoExtension.class})
class myCustomServiceTest
.
.
@Mock
private JobManager jobManager;
.private MyCustomService myCustomService = new MyCustomService ()
.
AemContext aemContext = new AemContext();
.
.
aemContext.registerService(JobManager);
aemContext.registerInjectActivateService(myCustomService); Line XX7
And i got a :
org.apache.sling.testing.mock.osgi.ReferenceViolationException: Unable to inject mandatory reference 'jobManager' ... no matching services were found at Line xx7.
PS : when i try to use :
AemContext aemContext = new AemContext(ResourceResolverType.JCR_OAK);
I have the following message :
java.lang.RuntimeException: Unable to initialize JCR_OAK resource resolver factory: Unable to instantiate resourcer resolver: org.apache.sling.testing.mock.sling.oak.OakMockResourceResolverAdapter. Make sure this maven dependency is included: org.apache.sling:org.apache.sling.testing.sling-mock-oak
Maybe could someone help me to understand : how do i have to mock a reference used in the service i want to test.
Thanks in advance.
