I'm using PowerMockito for mocking private method. But instead being mocked it is called. I need to test strangeMethod(), which calls privateMethod().
Here is my class for testing:
public class ExampleService {
public String strangeMethod() {
privateMethod();
return "Done!";
}
private String privateMethod() {
throw new UnsupportedOperationException();
}
}
My test method:
@Test
public void strangeMethodTest() throws Exception {
ExampleService exampleService = PowerMockito.spy(new ExampleService());
PowerMockito.when(exampleService, "privateMethod").thenReturn("");
exampleService.strangeMethod();
}
As a result of the test I'm getting UnsupportedOperationException. This means, that privateMethod() is called.
Aucun commentaire:
Enregistrer un commentaire