-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Description
Could you please show how I can verify the contents of an array?
In the following example, how can I verify the contents of the cities array?
@Test
public void testArrayHasExpectedItems() throws Exception {
String jsonAsString = "{" +
" \"cities\": [" +
" {" +
" \"name\": \"London\"," +
" \"size\": \"very big\"" +
" },{" +
" \"name\": \"Birmingham\"," +
" \"size\": \"big\"" +
" },{" +
" \"name\": \"Winchester\"," +
" \"size\": \"small\"" +
" }" +
" ]," +
" \"name\": \"United Kingdom\"" +
"}";
JsonNode json = new ObjectMapper().readTree(jsonAsString);
assertThat(json, is(
jsonObject()
.where("name", is(jsonText("United Kingdom")))
.where("cities", is(jsonArray()))
// How do I verify cities contains London?
));
}Metadata
Metadata
Assignees
Labels
No labels