Skip to content

Commit 3ab86af

Browse files
committed
Update JSONCompareTest.java
1 parent 7c9f6be commit 3ab86af

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.skyscreamer.jsonassert;
22

33
import static org.hamcrest.core.IsEqual.equalTo;
4+
import static org.junit.Assert.assertEquals;
45
import static org.junit.Assert.assertThat;
56
import static org.junit.Assert.assertTrue;
67
import static org.skyscreamer.jsonassert.JSONCompare.compareJSON;
@@ -32,18 +33,22 @@ public void reportsArraysOfUnequalLength() throws JSONException {
3233
public void reportsArrayMissingExpectedElement() throws JSONException {
3334
JSONCompareResult result = compareJSON("[4]", "[7]", LENIENT);
3435
assertThat(result, failsWithMessage(equalTo("[]\nExpected: 4\n but none found\n ; []\nUnexpected: 7\n")));
36+
assertEquals(result.getFieldMissing().size(), 1);
37+
assertEquals(result.getFieldUnexpected().size(), 1);
3538
}
3639

3740
@Test
3841
public void reportsMismatchedFieldValues() throws JSONException {
3942
JSONCompareResult result = compareJSON("{\"id\": 3}", "{\"id\": 5}", LENIENT);
4043
assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n")));
44+
assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n")));
4145
}
4246

4347
@Test
4448
public void reportsMissingField() throws JSONException {
4549
JSONCompareResult result = compareJSON("{\"obj\": {\"id\": 3}}", "{\"obj\": {}}", LENIENT);
4650
assertThat(result, failsWithMessage(equalTo("obj\nExpected: id\n but none found\n")));
51+
assertEquals(result.getFieldMissing().size(), 1);
4752
}
4853

4954
@Test
@@ -74,6 +79,7 @@ public void reportsUnexpectedNonNull() throws JSONException {
7479
public void reportsUnexpectedFieldInNonExtensibleMode() throws JSONException {
7580
JSONCompareResult result = compareJSON("{\"obj\": {}}", "{\"obj\": {\"id\": 3}}", NON_EXTENSIBLE);
7681
assertThat(result, failsWithMessage(equalTo("obj\nUnexpected: id\n")));
82+
assertEquals(result.getFieldUnexpected().size(), 1);
7783
}
7884

7985
@Test
@@ -86,13 +92,16 @@ public void reportsMismatchedTypes() throws JSONException {
8692
public void reportsWrongSimpleValueCountInUnorderedArray() throws JSONException {
8793
JSONCompareResult result = compareJSON("[5, 5]", "[5, 7]", LENIENT);
8894
assertThat(result, failsWithMessage(equalTo("[]: Expected 2 occurrence(s) of 5 but got 1 occurrence(s) ; []\nUnexpected: 7\n")));
95+
assertEquals(result.getFieldUnexpected().size(), 1);
8996
}
9097

9198
@Test
9299
public void reportsMissingJSONObjectWithUniqueKeyInUnorderedArray() throws JSONException {
93100
JSONCompareResult result = compareJSON("[{\"id\" : 3}]", "[{\"id\" : 5}]", LENIENT);
94101
assertThat(result, failsWithMessage(equalTo("[id=3]\nExpected: a JSON object\n but none found\n ; " +
95102
"[id=5]\nUnexpected: a JSON object\n")));
103+
assertEquals(result.getFieldMissing().size(), 1);
104+
assertEquals(result.getFieldUnexpected().size(), 1);
96105
}
97106

98107
@Test

0 commit comments

Comments
 (0)