简体   繁体   中英

java.lang.AssertionError: expected: org.json.JSONObject<{“feedback”:[]}> but was: org.json.JSONObject<{“feedback”:[]}>

I wrote a test of a method which have one condition. As per condition it should be empty and it is returning empty response but there is assertion error.

@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);
}

Getting following error:

java.lang.AssertionError: expected: org.json.JSONObject<{"feedback":[]}> but was: org.json.JSONObject<{"feedback":[]}>

Try to change your assertion like:

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

It should pass test now. For further details please click here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM