Skip to content
Permalink
Browse files

fix Static mocking broken for Mockito >= 2.26.1 (#997)

  • Loading branch information...
sam-ma authored and thekingnothing committed Aug 31, 2019
1 parent ad8ccad commit 37904cda43869b31d373309cc278fad97152ff91
@@ -22,18 +22,18 @@ buildscript {
ext{
gradleScriptDir = "${rootProject.projectDir}/gradle"

byteBuddy = "1.9.3"
byteBuddy = "1.9.10"
easymockVersion = "4.0.1"
hamcrestVersion = "1.3"
assertjVersion = "2.6.0"
cglibVersion = "3.2.9"
objenesisVersion = "3.0.1"
javassistVersion = "3.24.0-GA"
javassistVersion = "3.25.0-GA"
junitVersion = "4.12"
junitRulesVersion = "4.8.2"
testngVersion = "6.9.10"
xstreamVersion = "1.4.10"
mockitoVersion = "2.23.0"
mockitoVersion = "2.28.2"
servletVersion = "2.5"
jacocoVersion = "0.7.7.201606060606"
eclipseJdt = "3.3.0-v_771"
@@ -90,7 +90,11 @@ public Object invoke(final Object mock, final Method method, final Object[] argu
if (isCanBeHandledByMockito(method) && hasBeenCaughtByMockitoProxy()) {
returnValue = MockGateway.PROCEED;
} else {
returnValue = mockHandlerAdaptor.performIntercept(mock, method, arguments);
if (mock instanceof Class) {
returnValue = mockHandlerAdaptor.performIntercept(mockHandlerAdaptor.getMockSettings().getTypeToMock(), method, arguments);
} else {
returnValue = mockHandlerAdaptor.performIntercept(mock, method, arguments);
}
if (returnValue == null) {
return MockGateway.SUPPRESS;
}
@@ -29,11 +29,7 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.Mockito.times;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.mockStatic;
import static org.powermock.api.mockito.PowerMockito.spy;
import static org.powermock.api.mockito.PowerMockito.verifyStatic;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.powermock.api.mockito.PowerMockito.*;

/**
* Demonstrates PowerMockito's ability to mock non-final and final system
@@ -88,7 +84,8 @@ public void assertThatMockingOfFinalSystemClassesWorks() throws Exception {
public void assertThatPartialMockingOfFinalSystemClassesWorks() throws Exception {
spy(System.class);

when(System.nanoTime()).thenReturn(2L);
doReturn(2L).when(System.class);
System.nanoTime();

new SystemClassUser().doMoreComplicatedStuff();

@@ -112,10 +109,13 @@ public void assertThatMockingOfCollectionsWork() throws Exception {
public void assertThatPartialMockingOfFinalSystemClassesWorksForNonVoidMethods() throws Exception {
spy(System.class);

when(System.getProperty("property")).thenReturn("my property");
doReturn("my property").when(System.class);
System.getProperty("property");

final SystemClassUser systemClassUser = new SystemClassUser();
systemClassUser.copyProperty("to", "property");

assertEquals("my property", System.getProperty("to"));
}

@Test
@@ -82,7 +82,8 @@ public void assertThatMockingOfFinalSystemClassesWorks() throws Exception {
public void assertThatPartialMockingOfFinalSystemClassesWorks() throws Exception {
spy(System.class);

when(System.nanoTime()).thenReturn(2L);
doReturn(2L).when(System.class);
System.nanoTime();

new SystemClassUser().doMoreComplicatedStuff();

@@ -106,10 +107,13 @@ public void assertThatMockingOfCollectionsWork() throws Exception {
public void assertThatPartialMockingOfFinalSystemClassesWorksForNonVoidMethods() throws Exception {
spy(System.class);

when(System.getProperty("property")).thenReturn("my property");
doReturn("my property").when(System.class);
System.getProperty("property");

final SystemClassUser systemClassUser = new SystemClassUser();
systemClassUser.copyProperty("to", "property");

assertEquals("my property", System.getProperty("to"));
}

@Test
@@ -88,8 +88,9 @@ public void assertThatMockingOfFinalSystemClassesWorks() throws Exception {
@Test
public void assertThatPartialMockingOfFinalSystemClassesWorks() throws Exception {
spy(System.class);

when(System.nanoTime()).thenReturn(2L);

doReturn(2L).when(System.class);
System.nanoTime();

new SystemClassUser().doMoreComplicatedStuff();

@@ -112,11 +113,14 @@ public void assertThatMockingOfCollectionsWork() throws Exception {
@Test
public void assertThatPartialMockingOfFinalSystemClassesWorksForNonVoidMethods() throws Exception {
spy(System.class);

when(System.getProperty("property")).thenReturn("my property");

doReturn("my property").when(System.class);
System.getProperty("property");

final SystemClassUser systemClassUser = new SystemClassUser();
systemClassUser.copyProperty("to", "property");

assertEquals("my property", System.getProperty("to"));
}

@Test

0 comments on commit 37904cd

Please sign in to comment.
You can’t perform that action at this time.