Skip to content
This repository was archived by the owner on Apr 22, 2024. It is now read-only.
This repository was archived by the owner on Apr 22, 2024. It is now read-only.

Exercise 4 Part 2 AdvertisementControllerTest.readAll() unit test verification is not checking the value array #6

@mhnagaoka

Description

@mhnagaoka

In exercise 4, part 2, I changed the AdvertisementControllerTest.readAll() test a little bit:

    @Test
    public void readAll() throws Exception {

        // I changed this block to create 15 ads instead of just 1
        final int adCount = 15;
        for (int i = 0; i < adCount; i++) {
            mockMvc.perform(buildPostRequest(SOME_TITLE + "i"))
                .andExpect(status().isCreated());            
        }

        mockMvc.perform(buildGetRequest(""))
            .andExpect(status().isOk())
            .andExpect(content().contentType(APPLICATION_JSON_UTF8))
            .andExpect(jsonPath("$.length()", is(both(greaterThan(0)).and(lessThan(10)))));
    }

Given that I'm creating 15 ads, I was expecting the test to fail, but it didn't.
It seems that the JSON path verification line should be changed from:

.andExpect(jsonPath("$.length()", is(both(greaterThan(0)).and(lessThan(10)))));

to:

.andExpect(jsonPath("$.value.length()", is(greaterThanOrEqualTo(adCount))));

to count the number of elements of the value field in response JSON object.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions