मैं निजी स्थैतिक विधि anotherMethod()
नकली करने की कोशिश कर रहा हूं। नीचेमैं PowerMockito के साथ निजी स्थैतिक विधि का नकल कैसे कर सकता हूं?
public class Util {
public static String method(){
return anotherMethod();
}
private static String anotherMethod() {
throw new RuntimeException(); // logic was replaced with exception.
}
}
यहाँ कोड देखें मुझे परीक्षण कोड
@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");
}
}
लेकिन हर टाइल मैं इसे चलाने मैं इस अपवाद है
java.lang.AssertionError: expected object to not be null
मुझे लगता है कि मैं मजाक के साथ कुछ गलत कर रहा हूँ सामान। कोई विचार मैं इसे कैसे ठीक कर सकता हूं?
'के लिए TestNG' मैं अपने एनोटेशन का उपयोग की जरूरत नहीं।। – Aaron