Skip to content

How to verify items in an array? #49

Description

@vegemite4me

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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