-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
101 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/test/java/io/json/compare/matcher/diffs/JsonRealWorldDiffTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.json.compare.matcher.diffs; | ||
|
||
import io.json.compare.JSONCompare; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
public class JsonRealWorldDiffTests { | ||
|
||
@Test | ||
public void compareJsonObjectsAndCheckForDifferences() { | ||
String expected = "{\n" + | ||
" \"caught\": false,\n" + | ||
" \"pain\": {\n" + | ||
" \"range\": [\n" + | ||
" \"bell\",\n" + | ||
" \"blue\",\n" + | ||
" -2059921070\n" + | ||
" ],\n" + | ||
" \"not_anyone\": -1760889549.4041045,\n" + | ||
" \"flat\": -2099670336\n" + | ||
" }\n" + | ||
"}"; | ||
String actual = "{\n" + | ||
" \"caught\": true,\n" + | ||
" \"pain\": {\n" + | ||
" \"range\": [\n" + | ||
" \"bell\",\n" + | ||
" \"red\",\n" + | ||
" -2059921075\n" + | ||
" ],\n" + | ||
" \"anyone\": -1760889549.4041045,\n" + | ||
" \"flat\": -2099670336\n" + | ||
" },\n" + | ||
" \"broad\": \"invented\"\n" + | ||
"}"; | ||
AssertionError error = assertThrows(AssertionError.class, () -> JSONCompare.assertMatches(expected, actual)); | ||
assertTrue(error.getMessage().matches("(?s).*FOUND 4 DIFFERENCE.*" + | ||
"caught ->.*Expected value: false But got: true.*"+ | ||
"pain -> range ->.*Expected element from position 2 was NOT FOUND.*\"blue\".*"+ | ||
"pain -> range ->.*Expected element from position 3 was NOT FOUND.*-2059921070.*"+ | ||
"pain -> Field 'not_anyone' was NOT FOUND.*")); | ||
JSONCompare.assertNotMatches(expected, actual); | ||
} | ||
|
||
|
||
} |