java.lang.AssertionError:预期:org.json.JSONObject <{“ feedback”:[]}>但是是:org.json.JSONObject <{“ feedback”:[]}>

时间:2019-05-16 18:26:29

标签: java json maven spring-boot junit

我写了一个有一个条件的方法的测试。根据条件,它应该为空,并返回空响应,但存在断言错误。

@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":[]}>

1 个答案:

答案 0 :(得分:1)

尝试更改您的断言,例如:

assertEquals(expected.toString(), expected2.toString());

现在应该通过测试。有关更多详细信息,请click here

相关问题