rafael81 / powermock

Automatically exported from code.google.com/p/powermock
Apache License 2.0
0 stars 0 forks source link

PowerMockito: Mocking two static methods of two different classes breaks the first mocked static method when the second mocked method is called #542

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Please see the unit test below, the last assertion should not fail.

These versions are defined in Gradle:

testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.powermock:powermock-module-junit4:1.6.1'
testCompile 'org.powermock:powermock-api-mockito:1.6.1'

import android.content.Context; import android.text.format.DateFormat;

import junit.framework.TestCase;

import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner;

import java.text.SimpleDateFormat; import java.util.Calendar;

import static org.mockito.Matchers.any; import static org.powermock.api.mockito.PowerMockito.mock; import static org.powermock.api.mockito.PowerMockito.mockStatic; import static org.powermock.api.mockito.PowerMockito.when;

/**

Original issue reported on code.google.com by mob...@arnoldpistorius.com on 19 Feb 2015 at 3:22

GoogleCodeExporter commented 9 years ago
It seems for all assertions shouldMockThisCall in MockGateway.java:174 returns 
true, except for the last one (after thenCallRealMethod() is called).

The putAdditionalState("DontMockNextCall", true) in MockRepository.java:238 is 
called when callRealMethod is called on a non final system class 
(MockitoMethodInvocationControl.java:239).

The Javadoc says this is needed to prevent infinite recursion. But maybe this 
isn't the case for static methods???

Original comment by mob...@arnoldpistorius.com on 20 Feb 2015 at 8:47