Skip to content

Commit

Permalink
Fix for mockito#2235: use resolve() for the identity check
Browse files Browse the repository at this point in the history
  • Loading branch information
mschieder committed Mar 22, 2021
1 parent 1144eb4 commit 23cb966
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
Expand Up @@ -14,6 +14,7 @@
import org.mockito.internal.stubbing.OngoingStubbingImpl;
import org.mockito.internal.stubbing.StubbedInvocationMatcher;
import org.mockito.internal.stubbing.answers.DefaultAnswerValidator;
import org.mockito.internal.util.MockUtil;
import org.mockito.internal.verification.MockAwareVerificationMode;
import org.mockito.internal.verification.VerificationDataImpl;
import org.mockito.invocation.Invocation;
Expand Down Expand Up @@ -65,7 +66,7 @@ public Object handle(Invocation invocation) throws Throwable {
if (verificationMode != null) {
// We need to check if verification was started on the correct mock
// - see VerifyingWithAnExtraCallToADifferentMockTest (bug 138)
if (((MockAwareVerificationMode) verificationMode).getMock() == invocation.getMock()) {
if (MockUtil.areSameMocks(((MockAwareVerificationMode) verificationMode).getMock(), invocation.getMock())) {
VerificationDataImpl data =
new VerificationDataImpl(invocationContainer, invocationMatcher);
verificationMode.verify(data);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/org/mockito/internal/util/MockUtil.java
Expand Up @@ -120,6 +120,10 @@ private static Object resolve(Object mock) {
return mock;
}

public static boolean areSameMocks(Object mockA, Object mockB){
return mockA == mockB || resolve(mockA) == resolve(mockB);
}

public static MockName getMockName(Object mock) {
return getMockHandler(mock).getMockSettings().getMockName();
}
Expand Down

0 comments on commit 23cb966

Please sign in to comment.