Skip to content

jsonArray does not work correctly with hasItem() or hasItems() #25

@kmbyrne

Description

@kmbyrne

Reproducible with the following test:

@Test
public void testHasItems() throws IOException
{
	String jsonString = "[\n" +
							"  \"hello\", \"world\"\n" +
							"]";
	JsonNode json = new ObjectMapper().readTree(jsonString);
	assertThat(json, is(jsonArray(hasItem(is(jsonText("hello")))))); //this works
	assertThat(json, is(jsonArray(hasItem(is(jsonText("world")))))); //this does not
	assertThat(json, is(jsonArray(hasItems(is(jsonText("hello")))))); //this works
	assertThat(json, is(jsonArray(hasItems(is(jsonText("world")))))); //this does not
	assertThat(json, is(jsonArray(hasItems(is(jsonText("hello")), is(jsonText("world")))))); //this does not
	assertThat(json, is(jsonArray(contains(is(jsonText("hello")), is(jsonText("world")))))); //this works
}

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