Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/2235 verify on a wrapped mock fails #2236

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ libraries.junit4 = 'junit:junit:4.13.2'
libraries.junitJupiterApi = "org.junit.jupiter:junit-jupiter-api:${versions.junitJupiter}"
libraries.junitPlatformLauncher = 'org.junit.platform:junit-platform-launcher:1.7.1'
libraries.junitJupiterEngine = "org.junit.jupiter:junit-jupiter-engine:${versions.junitJupiter}"
libraries.junitVintageEngine = "org.junit.vintage:junit-vintage-engine:${versions.junitJupiter}"
libraries.assertj = 'org.assertj:assertj-core:3.19.0'
libraries.hamcrest = 'org.hamcrest:hamcrest-core:2.2'
libraries.opentest4j = 'org.opentest4j:opentest4j:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
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,9 @@ 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
Original file line number Diff line number Diff line change
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
6 changes: 6 additions & 0 deletions subprojects/extTest/extTest.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ dependencies {
testCompile libraries.junit4
testCompile libraries.assertj
testCompile libraries.junitJupiterApi
testRuntime libraries.junitJupiterEngine
testRuntime libraries.junitVintageEngine
}

tasks.withType(Test) {
useJUnitPlatform()
}

configurations.all {
Expand Down