public class TestedClass
{
public void publicMethod()
{
privateMethod();
}
private void privateMethod()
{
}
}
I would like to test with PowerMockito that the private method is called exactly once.
Here's my test class:
@RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.management.*")
public class TestedClassTest
{
@Before
public void setUp()
{
}
@Test
public void testPrivateMethodCalledOnce() throws Exception
{
TestedClass spy = PowerMockito.spy(new TestedClass());
spy.publicMethod();
PowerMockito.verifyPrivate(spy, Mockito.times(772)).invoke("privateMethod");
}
}
Despite only being called once this test passes. Even if I comment privateMethod inside the public method the test seems too pass.
public class TestedClass
{
public void publicMethod()
{
//privateMethod(); <-- test still passes
}
private void privateMethod()
{
}
}
Does anyone have an idea what I did wrong? And does anyone know how to verify that the private method was called exactly once in the unit test?