Sto provando a prendere in giro il metodo statico privato anotherMethod()
. Vedere codice qui sottoCome posso prendere in giro il metodo statico privato con PowerMockito?
public class Util {
public static String method(){
return anotherMethod();
}
private static String anotherMethod() {
throw new RuntimeException(); // logic was replaced with exception.
}
}
Ecco me è il codice di prova
@PrepareForTest(Util.class)
public class UtilTest extends PowerMockTestCase {
@Test
public void should_prevent_invoking_of_private_method_but_return_result_of_it() throws Exception {
PowerMockito.mockStatic(Util.class);
PowerMockito.when(Util.class, "anotherMethod").thenReturn("abc");
String retrieved = Util.method();
assertNotNull(retrieved);
assertEquals(retrieved, "abc");
}
}
Ma ogni piastrella l'eseguo ottengo questa eccezione
java.lang.AssertionError: expected object to not be null
Suppongo che sto facendo qualcosa di sbagliato con beffarda cose. Qualche idea come posso risolverlo?
No. Per 'TestNG' ho bisogno di usare le mie annotazioni. – Aaron