我写了一个有一个条件的方法的测试。根据条件,它应该为空,并返回空响应,但存在断言错误。
@Test
public void testExtractData_feedbackRecords_withBadWords() throws Exception {
//given
JSONArray tags = new JSONArray();
tags.put("ios_pre");
tags.put("andr_pre");
tags.put("web_pre");
JSONObject jsonObject = new JSONObject();
jsonObject.put("group_id", "28430278");
jsonObject.put("created_at", "2019-04-05T00:00:00Z");
jsonObject.put("updated_dt", "");
jsonObject.put("status", "status-test");
jsonObject.put("ticket_id", "1");
jsonObject.put("id", "1");
jsonObject.put("description", "----- Sender Info ----- Body:body1 adult platform=platform1");
JSONArray feedbackRecords = new JSONArray();
feedbackRecords.put(jsonObject);
JSONArray empty = new JSONArray();
JSONObject expected = new JSONObject();
expected.put("feedback", empty);
ZendeskExtractor mockZendeskExtractor = PowerMockito.mock(ZendeskExtractor.class);
PowerMockito.doReturn(feedbackRecords)
.when(mockZendeskExtractor, "extractFeedback", Mockito.any(String.class), Mockito.any(String.class));
when(mockZendeskExtractor.extractData("2019-04-05T00:00:00Z", DateTime.parse("2019-04-25T00:00:00Z")))
.thenCallRealMethod();
//when
JSONObject actualData =
mockZendeskExtractor.extractData("2019-04-05T00:00:00Z", DateTime.parse("2019-04-25T00:00:00Z"));
//then
assertEquals(expected, actualData);
}
出现以下错误:
java.lang.AssertionError: expected: org.json.JSONObject<{"feedback":[]}> but was: org.json.JSONObject<{"feedback":[]}>
答案 0 :(得分:1)