我有一个带有私有静态方法的最终类,它在另一个静态方法中调用
public final class GenerateResponse{
private static Map<String, String> getErrorDetails(JSONObject jsonObject) {
// implementation
}
public static String method1(params...){
Map<String, String> map = getErrorDetails(new JsonObject());
// implementation
}
}
我需要模拟私有静态方法调用getErrorDetails()
,但我的测试是调用实际方法。这是我的代码:
@RunWith(PowerMockRunner.class)
@PrepareForTest(GenerateResponse.class)
public class GenerateResponseTest{
@Test
public void testFrameQtcErrorResponse() throws Exception {
Map<String, String> errorDtls = new HashMap<String, String>();
PowerMockito.spy(GenerateResponse.class);
PowerMockito.doReturn(errorDtls).when(GenerateResponse.class, "getErrorDetails", JSONObject.class);
String response = GenerateResponse.method1(params...);
}