jeudi 4 mars 2021

Expected response has response object in it

I'm running into an issue with a test case where the actual response isn't matching the expected response, due to the response object being a part of the expected response. The 'Actual' response is correct, but I'm unsure how to adapt my test case (and how I'm forming the expected result) to resolve it.

    protected ResponseObject createResponseObject(){
        return ResponseObject
                .builder()
                .id(TEST_PROJECT_ID)
                .activity(TEST_ACTIVITY)
                .name(TEST_PROJECT_NAME)
                .status(TEST_STATUS)
                .build();
    }

        List<ResponseObject> expectedResponseObject = new ArrayList();
        expectedResponseObject.add(createResponseObject());

assertEquals(expectedResponseObject, actualResponse);
java.lang.AssertionError: 
Expected :[ResponseObject(id=1, name=test_project, status=ACTIVE, activity=NOT_STARTED)]
Actual   :[{id=1, name=test_project, status=ACTIVE, activity=NOT_STARTED}]

The actual response is being mocked

        MockHttpServletResponse response = mockMvc
                .perform(get(GET_PROJECTS).contentType(MediaType.APPLICATION_JSON)
                        .content(jacksonTester.write("")
                                .getJson()))
                .andReturn().getResponse();
        List<ResponseObject> actualResponse = objectMapper
                .readValue(response.getContentAsString(), List.class);

Aucun commentaire:

Enregistrer un commentaire