I just upgraded our AEM codebase to use JUnit 5 but we are having some issues with some tests mocking specific methods of the LanguageManager.
@MockitoSettings(strictness = Strictness.LENIENT)
@ExtendWith({AemContextExtension.class, MockitoExtension.class})
public class SomeComponentTest {
@Mock
private LanguageManager languageManager;
@BeforeEach
public void setUp() throws Exception {
...
context.registerService(LanguageManager.class, languageManager);
...
}
@Test
public void someTest() {
...
Page mockPage = mock(Page.class);
given(languageManager.getLanguageRoot(any())).willReturn(mockPage);
...
}
}
Even though I register the LanguageManager mock it still seem to get the WCM IO provided mock, which is initialized here: https://github.com/wcm-io/wcm-io-testing/blob/develop/aem-mock/core/src/main/java/io/wcm/testing/mock/aem/context/AemContextImpl.java -> registerInjectActivateService(new MockLanguageManager());
Am I doing something wrong here or is there just no way to spy / mock the methods of the LanguageManager. Do note that in the past this worked when using:
@RunWith(MockitoJUnitRunner.class)
Aucun commentaire:
Enregistrer un commentaire