Skip to content

Commit

Permalink
Better array comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Dec 10, 2017
1 parent c72f44e commit 66ab10d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ private void compareArrayNodes(Node expectedNode, Node actualNode, String path)
structureDifferenceFound("Array \"%s\" has different length, expected: <%d> but was: <%d>.", path, expectedElements.size(), actualElements.size());
}
} else {
// if we expect more elements in the array then we get, it's error even when IGNORING_EXTRA_ARRAY_ITEMS
// if we expect more elements in the array than we get, it's error even when IGNORING_EXTRA_ARRAY_ITEMS
if (expectedElements.size() > actualElements.size()) {
structureDifferenceFound("Array \"%s\" has invalid length, expected: <at least %d> but was: <%d>.", path, expectedElements.size(), actualElements.size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ public void testDifferentArrayLength() {
}
}

@Test
public void testDifferentArrayLengthWhenIgnoringArrayOrder() {
try {
assertJsonEquals("{\"test\":[\"a\", \"b\", \"c\"]}", "{\n\"test\": [\"a\", \"b\"]\n}", when(IGNORING_ARRAY_ORDER));
failIfNoException();
} catch (AssertionError e) {
assertEquals("JSON documents are different:\n" +
"Array \"test\" has different length, expected: <3> but was: <2>.\n" +
"Array \"test\" has different content, expected: <[\"a\",\"b\",\"c\"]> but was: <[\"a\",\"b\"]>. Missing values [\"c\"], extra values []\n", e.getMessage());
}
}

@Test
public void testDifferentArrayValue() {
try {
Expand Down

0 comments on commit 66ab10d

Please sign in to comment.