Skip to content

Commit

Permalink
#483 Support JsonPath in whenIgnoringPaths
Browse files Browse the repository at this point in the history
  • Loading branch information
lukas-krecan committed Feb 20, 2024
1 parent 62d692c commit f524657
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private static class SimplePathMatcher extends PathMatcher {

@Override
boolean matches(String pathToMatch) {
return path.equals(pathToMatch) || path.equals("$." + pathToMatch);
return path.equals(pathToMatch) || path.equals("$." + pathToMatch) || path.equals("$" + pathToMatch);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,14 @@ void shouldIgnoreArrayElement() {
assertThatJson("{\"root\":[0, 1, 2]}").whenIgnoringPaths("root[1]").isEqualTo("{\"root\":[0, 8, 2]}");
}

@Test
void shouldIgnoreJsonPaths() {
String expected = "[{\"name\":\"123\",\"age\":2},{\"name\":\"321\",\"age\":5}]";
String actual = "[{\"name\":\"123\",\"age\":5},{\"name\":\"321\",\"age\":8}]";

assertThatJson(expected).whenIgnoringPaths("$..age").isEqualTo(actual);
}

@Test
void arraySimpleIgnoringOrderNotEqualComparison() {
assertThatJson("{\"a\":[{\"b\": 1}, {\"c\": 1}, {\"d\": 1}]}")
Expand Down

0 comments on commit f524657

Please sign in to comment.