You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
we are using mockito 4.8.1 on jdk 11 targeting java 8
recently one of our maven modules added a dependency to mockito-inline in order to mock final classes/methods (normally modules use normal mockito)
we started seeing sporadically failing tests around this:
java.lang.AssertionError
at org.mockito.internal.util.MockUtil.getMockHandlerOrNull(MockUtil.java:160)
at org.mockito.internal.util.MockUtil.getMockHandler(MockUtil.java:115)
at org.mockito.internal.stubbing.answers.InvocationInfo.isVoid(InvocationInfo.java:94)
at org.mockito.internal.stubbing.answers.Returns.validateFor(Returns.java:34)
at org.mockito.internal.stubbing.InvocationContainerImpl.addAnswer(InvocationContainerImpl.java:65)
at org.mockito.internal.stubbing.InvocationContainerImpl.addAnswer(InvocationContainerImpl.java:56)
at org.mockito.internal.stubbing.OngoingStubbingImpl.thenAnswer(OngoingStubbingImpl.java:32)
at org.mockito.internal.stubbing.BaseStubbing.thenReturn(BaseStubbing.java:34)
(..)
also:
java.lang.AssertionError
at org.mockito.internal.util.MockUtil.getMockHandlerOrNull(MockUtil.java:160)
at org.mockito.internal.util.MockUtil.isMock(MockUtil.java:147)
at org.mockito.internal.stubbing.StubberImpl.when(StubberImpl.java:43)
(..)
for the latter error the test code looks like this:
import com.azure.resourcemanager.AzureResourceManager;
import com.azure.resourcemanager.compute.models.GalleryImageVersions;
(..)
@Test
public void testMethod() {
AzureResourceManager mockArmClient = mock(AzureResourceManager.class); // final class
GalleryImageVersions mockGalleryImageVersions = mock(GalleryImageVersions.class); // interface
doReturn(mockGalleryImageVersions).when(mockArmClient).galleryImageVersions();
doReturn(null).when(mockGalleryImageVersions).listByGalleryImage(anyString(), anyString(), anyString()); <- assertion fails here
(..)
}
additional notes:
these tests are not failing every time and the number of failing tests varies (but all with assertion error in MockUtil.getMockHandlerOrNull)
in case it is relevant: it could be that the maven module depends on both <artifactId>mockito-inline</artifactId> and <artifactId>mockito-core</artifactId> but these tests are not using multiple classloaders or the like
are we doing anything wrong or is this a mockito bug?
the full code is from a large private codebase, so i tried to distill it down to a minimal public example however now the error does not occur anymore with the mentioned code... (was running the test in a loop in 4 shells).
do you have any remote idea when this assertion might be failing?
when does mockMakers.values() return more than 1 element?
could it be related to classloader shenanigans maybe (i.e. Thread.currentThread().getContextClassLoader()) ?
Seems like this is a similar issue to #2823 In your large codebase, it is likely that you have clashing usages of mockmakers, triggering this assertion. Hopefully that additional information can help you further debug this issue.
hello,
we are using mockito 4.8.1 on jdk 11 targeting java 8
recently one of our maven modules added a dependency to
mockito-inline
in order to mock final classes/methods (normally modules use normal mockito)we started seeing sporadically failing tests around this:
also:
for the latter error the test code looks like this:
additional notes:
MockUtil.getMockHandlerOrNull
)<artifactId>mockito-inline</artifactId>
and<artifactId>mockito-core</artifactId>
but these tests are not using multiple classloaders or the likeare we doing anything wrong or is this a mockito bug?
the failing assertion has only recently been added in 4.8.0 for supporting the mockmaker settings:
https://github.com/mockito/mockito/blame/3faa00299a8c0793cf17ce072229f2e8ffea4579/src/main/java/org/mockito/internal/util/MockUtil.java#L160
any ideas when this can resolve to different mock makers?
The text was updated successfully, but these errors were encountered: