PowerMock mock 静态方法
静态方法内部有调用,先Mock内部方法,再正常调用
public void testUpdateInfo() { // Setup final Config config = new Config(); try{ final JSONObject expectedResult = new JSONObject(0, false); expectedResult.put("code", "200"); PowerMockito.mockStatic(HttpUtils.class); PowerMockito.when(HttpUtils.postForObject(Mockito.anyString(), Mockito.anyMap(), Mockito.any())).thenReturn(expectedResult.toString()); // Run the test final JSONObject result = TodoUtil.updateInfo(config, "recordRequest"); // Verify the results assertEquals(expectedResult, result); }catch (Exception e) { e.printStackTrace(); } }