Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
fslev committed Oct 3, 2022
1 parent ef815c4 commit 7c60b0e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/main/java/io/json/compare/JSONCompare.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static void assertMatches(Object expected, Object actual, JsonComparator
if (!diffs.isEmpty()) {
String defaultMessage = String.format("FOUND %s DIFFERENCE(S):\n%s\n",
diffs.size(), diffs.stream().map(diff ->
"\n_________________________DIFF__________________________\n" + diff).reduce(String::concat).get());
"\n\n_________________________DIFF__________________________\n" + diff).reduce(String::concat).get());
if (comparator == null || comparator.getClass().equals(DefaultJsonComparator.class)) {
defaultMessage += "\n\n" + ASSERTION_ERROR_HINT_MESSAGE + "\n";
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/json/compare/matcher/JsonArrayMatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private List<String> matchWithJsonArray(int expPosition, JsonNode expElement, Js
return Collections.emptyList();
} else {
if (compareModes.contains(CompareMode.JSON_ARRAY_STRICT_ORDER)) {
diffs.add(String.format("\nJSON ARRAY elements differ at position %s:\n%s\n________diffs________\n%s", expPosition + 1,
diffs.add(String.format("JSON ARRAY elements differ at position %s:\n%s\n________diffs________\n%s", expPosition + 1,
MessageUtil.cropL(JSONCompare.prettyPrint(expElement)), String.join("\n_____________________\n", elementDiffs)));
return diffs;
}
Expand All @@ -69,14 +69,14 @@ private List<String> matchWithJsonArray(int expPosition, JsonNode expElement, Js
if (areOfSameType(expElement, actElement)) {
elementDiffs = new JsonMatcher(expElement, actElement, comparator, compareModes).match();
if (!elementDiffs.isEmpty()) {
diffs.add("\nExpected element from position " + (expPosition + 1)
diffs.add("Expected element from position " + (expPosition + 1)
+ " was FOUND:\n" + MessageUtil.cropL(JSONCompare.prettyPrint(expElement)));
return diffs;
}
}
break;
case DO_NOT_MATCH_ANY:
diffs.add(String.format("\nExpected condition %s from position %s was not met." +
diffs.add(String.format("Expected condition %s from position %s was not met." +
" Actual JSON array has extra elements.",
expElement, expPosition + 1));
return diffs;
Expand All @@ -86,7 +86,7 @@ private List<String> matchWithJsonArray(int expPosition, JsonNode expElement, Js
diffs.add("\nExpected element from position " + (expPosition + 1) + " was NOT FOUND:\n"
+ MessageUtil.cropL(JSONCompare.prettyPrint(expElement)));
} else if (useCase == UseCase.MATCH_ANY) {
diffs.add(String.format("\nExpected condition %s from position %s was not met." +
diffs.add(String.format("Expected condition %s from position %s was not met." +
" Actual Json Array has no extra elements.", expElement, expPosition + 1));
}
return diffs;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class JsonValueMatcher extends AbstractJsonMatcher {
@Override
public List<String> match() {
List<String> diffs = new ArrayList<>();
String diff = "\nExpected %s: %s But got: %s";
String diff = "Expected %s: %s But got: %s";

if (expected.isNull() && !actual.isNull()) {
diffs.add(String.format(diff, "null", "", actual));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,9 @@ public void checkInvalidOrNotFoundJsonPathErrorMessage() {
try {
JSONCompare.assertMatches(expected, actual);
} catch (AssertionError e) {
assertTrue(e.getMessage().contains("FOUND 1 DIFFERENCE(S):\n" +
"\n" +
"_________________________DIFF__________________________\n" +
"a -> a1 -> a11 -> json path ('$.idontexist') -> No results for path: $['idontexist']"));
assertTrue(e.getMessage().matches("(?s).*FOUND 1 DIFFERENCE.*" +
"_________________________DIFF__________________________.*" +
"\\Qa -> a1 -> a11 -> json path ('$.idontexist') -> No results for path: $['idontexist']\\E.*"));
return;
}
fail("No error thrown");
Expand Down

0 comments on commit 7c60b0e

Please sign in to comment.