Skip to content

Commit d9278b2

Browse files
committed
Upgrade Mockito to 5.X
1 parent adf586c commit d9278b2

13 files changed

Lines changed: 40 additions & 23 deletions

File tree

dexmaker-mockito-inline-extended-tests/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ dependencies {
3030
androidTestImplementation 'androidx.test:runner:1.4.0'
3131
androidTestImplementation 'androidx.test:rules:1.4.0'
3232

33-
androidTestImplementation 'org.mockito:mockito-core:2.28.2', { exclude group: 'net.bytebuddy' }
33+
androidTestImplementation libs.mockito.core, { exclude group: 'net.bytebuddy' }
3434
}

dexmaker-mockito-inline-extended-tests/src/androidTest/java/com/android/dx/mockito/inline/extended/tests/MockStatic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
2626
import static com.android.dx.mockito.inline.extended.ExtendedMockito.reset;
2727
import static com.android.dx.mockito.inline.extended.ExtendedMockito.staticMockMarker;
28-
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyZeroInteractions;
28+
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoInteractions;
2929
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
3030

3131
import static org.junit.Assert.assertEquals;
@@ -401,7 +401,7 @@ public void clearInvocationsRemovedInvocations() throws Exception {
401401
try {
402402
SuperClass.returnB();
403403
clearInvocations(staticMockMarker(SuperClass.class));
404-
verifyZeroInteractions(staticMockMarker(SuperClass.class));
404+
verifyNoInteractions(staticMockMarker(SuperClass.class));
405405
} finally {
406406
session.finishMocking();
407407
}

dexmaker-mockito-inline-extended-tests/src/androidTest/java/com/android/dx/mockito/inline/extended/tests/StaticMockitoSessionVsMockitoJUnitRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import org.junit.runner.RunWith;
2121
import org.mockito.junit.MockitoJUnitRunner;
2222

23-
@RunWith(MockitoJUnitRunner.class)
23+
@RunWith(MockitoJUnitRunner.Silent.class)
2424
public class StaticMockitoSessionVsMockitoJUnitRunner {
2525
@Test
2626
public void simpleStubbing() throws Exception {

dexmaker-mockito-inline-extended-tests/src/androidTest/java/com/android/dx/mockito/inline/extended/tests/VerifyStatic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import static com.android.dx.mockito.inline.extended.ExtendedMockito.staticMockMarker;
3131
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verify;
3232
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoMoreInteractions;
33-
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyZeroInteractions;
33+
import static com.android.dx.mockito.inline.extended.ExtendedMockito.verifyNoInteractions;
3434
import static com.android.dx.mockito.inline.extended.ExtendedMockito.when;
3535
import static org.junit.Assert.assertEquals;
3636
import static org.junit.Assert.assertNull;
@@ -180,7 +180,7 @@ public void zeroInvocationsThrowsIfThereWasAnInvocation() throws Exception {
180180
MockitoSession session = mockitoSession().mockStatic(EchoClass.class).startMocking();
181181
try {
182182
EchoClass.echo("marco!");
183-
verifyZeroInteractions(staticMockMarker(EchoClass.class));
183+
verifyNoInteractions(staticMockMarker(EchoClass.class));
184184
fail();
185185
} finally {
186186
session.finishMocking();

dexmaker-mockito-inline-extended/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ dependencies {
4646

4747
implementation project(':dexmaker-mockito-inline')
4848

49-
api 'org.mockito:mockito-core:2.28.2', { exclude group: 'net.bytebuddy' }
49+
api libs.mockito.core, { exclude group: 'net.bytebuddy' }
5050
}

dexmaker-mockito-inline-extended/src/main/java/com/android/dx/mockito/inline/extended/StaticInOrder.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.android.dx.mockito.inline.extended;
1818

1919
import org.mockito.InOrder;
20+
import org.mockito.MockedStatic;
2021
import org.mockito.Mockito;
2122
import org.mockito.verification.VerificationMode;
2223

@@ -141,6 +142,12 @@ public void verify(MockedMethod method, VerificationMode mode) {
141142
verify((MockedVoidMethod) method::get, mode);
142143
}
143144

145+
@Override
146+
public void verify(MockedStatic<?> mockedStatic, MockedStatic.Verification verification,
147+
VerificationMode mode) {
148+
instanceInOrder.verify(mockedStatic, verification, mode);
149+
}
150+
144151
@Override
145152
public void verifyNoMoreInteractions() {
146153
instanceInOrder.verifyNoMoreInteractions();

dexmaker-mockito-inline-tests/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,5 @@ dependencies {
3030

3131
androidTestImplementation 'junit:junit:4.13.2'
3232
androidTestImplementation 'androidx.test:runner:1.4.0'
33-
androidTestImplementation 'org.mockito:mockito-core:2.28.2', { exclude group: 'net.bytebuddy' }
33+
androidTestImplementation libs.mockito.core, { exclude group: 'net.bytebuddy' }
3434
}

dexmaker-mockito-inline/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,5 @@ dependencies {
4141

4242
implementation project(':dexmaker')
4343

44-
api 'org.mockito:mockito-core:2.28.2', { exclude group: 'net.bytebuddy' }
44+
api libs.mockito.core, { exclude group: 'net.bytebuddy' }
4545
}

dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/JvmtiAgent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class JvmtiAgent {
8080
private static String resolveAgentPath(ClassLoader cl) throws IOException {
8181
String path = ((BaseDexClassLoader) cl).findLibrary("dexmakerjvmtiagent");
8282

83-
if (path != null && !path.contains("=")) {
83+
if (path != null && !path.contains("=") && !path.contains("!")) {
8484
return path;
8585
}
8686

dexmaker-mockito-inline/src/main/java/com/android/dx/mockito/inline/MockMakerMultiplexer.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.mockito.plugins.InlineMockMaker;
2424
import org.mockito.plugins.MockMaker;
2525

26-
import java.lang.reflect.InvocationTargetException;
2726
import java.util.ArrayList;
2827

2928
/**
@@ -36,7 +35,7 @@ public final class MockMakerMultiplexer implements InlineMockMaker {
3635
static {
3736
String[] potentialMockMakers = new String[] {
3837
"com.android.dx.mockito.inline.InlineStaticMockMaker",
39-
InlineDexmakerMockMaker.class.getName()
38+
"com.android.dx.mockito.inline.InlineDexmakerMockMaker"
4039
};
4140

4241
ArrayList<MockMaker> mockMakers = new ArrayList<>();
@@ -45,14 +44,10 @@ public final class MockMakerMultiplexer implements InlineMockMaker {
4544
Class<? extends MockMaker> mockMakerClass = (Class<? extends MockMaker>)
4645
Class.forName(potentialMockMaker);
4746
mockMakers.add(mockMakerClass.getDeclaredConstructor().newInstance());
48-
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
49-
| NoSuchMethodException | InvocationTargetException e) {
50-
if (potentialMockMaker.equals(InlineDexmakerMockMaker.class.getName())) {
51-
Log.e(LOG_TAG, "Could not init mockmaker " + potentialMockMaker, e);
52-
} else {
53-
// Additional mock makers might not be loaded
54-
Log.e(LOG_TAG, "Could not init mockmaker " + potentialMockMaker);
55-
}
47+
} catch (Exception e) {
48+
Log.e(LOG_TAG, "Could not init mockmaker " + potentialMockMaker, e);
49+
} catch (Error e) {
50+
Log.e(LOG_TAG, "Could not init mockmaker " + potentialMockMaker, e);
5651
}
5752
}
5853

@@ -102,7 +97,17 @@ public TypeMockability isTypeMockable(Class<?> type) {
10297
}
10398
}
10499

105-
return null;
100+
return new TypeMockability() {
101+
@Override
102+
public boolean mockable() {
103+
return false;
104+
}
105+
106+
@Override
107+
public String nonMockableReason() {
108+
return "No mock makers available to mock this type";
109+
}
110+
};
106111
}
107112

108113
@Override

0 commit comments

Comments
 (0)