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
My unit test had a call final SomeObject someObject = someClass.someMethod(someObjects1, someObjects2, mock(SomeMockedClass.class));
that lead to:
java.lang.NullPointerException: Cannot invoke "java.util.Set.iterator()" because the return value of "java.util.Map.entrySet()" is null
at org.mockito.internal.matchers.text.ValuePrinter.printMap(ValuePrinter.java:83)
at org.mockito.internal.matchers.text.ValuePrinter.print(ValuePrinter.java:49)
at org.mockito.internal.matchers.Equals.describe(Equals.java:36)
at org.mockito.internal.matchers.Equals.toString(Equals.java:32)
at org.mockito.internal.matchers.text.MatcherToString.toString(MatcherToString.java:33)
at org.mockito.internal.matchers.text.MatchersPrinter.applyPrintSettings(MatchersPrinter.java:50)
at org.mockito.internal.matchers.text.MatchersPrinter.getArgumentsLine(MatchersPrinter.java:19)
at org.mockito.internal.reporting.PrintSettings.print(PrintSettings.java:60)
at org.mockito.internal.invocation.InterceptedInvocation.toString(InterceptedInvocation.java:193)
at java.base/java.lang.String.valueOf(String.java:4465)
at java.base/java.lang.StringBuilder.append(StringBuilder.java:173)
at org.mockito.internal.exceptions.Reporter.potentialStubbingProblem(Reporter.java:1080)
at org.mockito.internal.junit.DefaultStubbingLookupListener.onStubbingLookup(DefaultStubbingLookupListener.java:55)
at org.mockito.internal.listeners.StubbingLookupNotifier.notifyStubbedAnswerLookup(StubbingLookupNotifier.java:31)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:93)
at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:34)
at org.mockito.internal.creation.bytebuddy.MockMethodInterceptor.doIntercept(MockMethodInterceptor.java:82)
at org.mockito.internal.creation.bytebuddy.MockMethodAdvice.handle(MockMethodAdvice.java:134)
at first-line-of-a-method-under-tested-user-code)
`
providing the right mocked object (the one defined with @ Mock annotation and was used in the when conditions) solve the issue: final SomeObject someObject = someClass.someMethod(someObjects1, someObjects2, someMockedClass);
However, I would expect a user friendly message in the stacktrace, explain I was using the wrong mocked object.
tested with:
mockito version 4.11.0
openjdk version "17.0.10" 2024-01-16 LTS
Mac OS X 14.4.1
The text was updated successfully, but these errors were encountered:
My unit test had a call
final SomeObject someObject = someClass.someMethod(someObjects1, someObjects2, mock(SomeMockedClass.class));
that lead to:
`
providing the right mocked object (the one defined with @ Mock annotation and was used in the when conditions) solve the issue:
final SomeObject someObject = someClass.someMethod(someObjects1, someObjects2, someMockedClass);
However, I would expect a user friendly message in the stacktrace, explain I was using the wrong mocked object.
tested with:
mockito version 4.11.0
openjdk version "17.0.10" 2024-01-16 LTS
Mac OS X 14.4.1
The text was updated successfully, but these errors were encountered: