What steps will reproduce the problem?
1. Create a mock for a class with a protected method with 3 or more parameters
of differing type using PowerMockito.
2. Mock a return a value for the method. This raises a NullPointerException
when specific matchers are used.
What is the expected output? What do you see instead?
NullPointerException is not expected.
What version of the product are you using? On what operating system?
Ubuntu 9.10
mockitio-all-1.8.5.jar
powermock-mockito-1.4.6-full.jar
Please provide any additional information below.
The following code reproduces the problem:
package test;
public class ClassUnderTest {
protected String methodUnderTest(boolean param1, String param2, String param3) {
return "real value";
}
}
package test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
@RunWith(PowerMockRunner.class)
@PrepareForTest( {ClassUnderTest.class} )
public class SimpleTest {
@Test
public void testMethodUnderTest( ) throws Exception {
String testValue = "test value";
String testMethod = "methodUnderTest";
ClassUnderTest mockObject = PowerMockito.mock(ClassUnderTest.class);
// This works
PowerMockito.doReturn( testValue ).when( mockObject, testMethod, eq(false), eq(" "), eq(null) );
// But this doesn't
PowerMockito.doReturn( testValue ).when( mockObject, testMethod, eq(false), anyString(), eq(null) );
}
}
Original issue reported on code.google.com by richard%...@gtempaccount.com on 19 Nov 2010 at 10:13
Original issue reported on code.google.com by
richard%...@gtempaccount.com
on 19 Nov 2010 at 10:13