I have a legacy class which has a static void method which i need to test:
public class A {
public static void renameTo()
{
String ext = "." + this.fileName + ".backup";
for (File file : getCSVFile()) {
f.renameTo(new File(file.getAbsolutePath() + ext));
}
public static File[] getAllFiles()
{
//logic to read the CSV files from the class path
}
}
Now I have written a test case for it using PowerMockito which looks like this. Now the issue is, even though the renameTo()
is called only, if i call PowerMockito.verifyStatic( Mockito.times(10))
the test still passes
@RunWith(PowerMockRunner.class)
@PrepareForTest(A.class)
@PowerMockIgnore("javax.management.*")
public class ATest {
@Test
public void testRenameTo() throws Exception {
PowerMockito.mockStatic(A.class);
A.renameTo();
PowerMockito.verifyStatic( Mockito.times(1));
//PowerMockito.verifyStatic( Mockito.times(5));//Passes even though the mehod is called only once
//PowerMockito.verifyStatic( Mockito.times(10);//Passes even though the mehod is called only once
}
}
Could someone please shed some light into this issue? what I may be doing wrong?