Özel statik yöntem anotherMethod()
ile uğraşmaya çalışıyorum. İştePowerMockito ile özel statik yöntemi nasıl kullanabilirim?
public class Util {
public static String method(){
return anotherMethod();
}
private static String anotherMethod() {
throw new RuntimeException(); // logic was replaced with exception.
}
}
aşağıdaki kodu bakın bana
@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");
}
}
Ama bunu çalıştırmak her kiremit bu istisna olsun sınav kodudur
java.lang.AssertionError: expected object to not be null
ben alay ile yanlış bir şey yapıyorum varsayalım şey. Herhangi bir fikri nasıl tamir edebilirim?
sayılı. – Aaron