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

Description
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.