I need to mock a static method only in one test case and wants it to return the original value in all the other testcases.
Class ClassWithStaticMethod
{
public static boolean aStaticMethod(String param)
{
//Some Code;
return value;
}
}
/// Test Class
@RunWith(PowerMockRunner.class)
Class ClassWithStaticMethodTest
{
@Test
testWhenNotMocked()
{
assertTrue(ClassWithStaticMethod.aStaticMethod("str1"));
}
@PrepareForTest({ClassWithStaticMethod.class})
@Test
testWhenMocked()
{
PowerMockito.mockStatic(ClassWithStaticMethod.class);
when(ClassWithStaticMethod.aStaticMethod("str1")).thenReturn(false);
assertFalse(ClassWithStaticMethod.aStaticMethod("str1"));
}
}
But the code is always returning false.