11package org .skyscreamer .jsonassert ;
22
33import static org .hamcrest .core .IsEqual .equalTo ;
4+ import static org .junit .Assert .assertEquals ;
45import static org .junit .Assert .assertThat ;
56import static org .junit .Assert .assertTrue ;
67import 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 ("[]\n Expected: 4\n but none found\n ; []\n Unexpected: 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\n Expected: 3\n got: 5\n " )));
44+ assertThat (result , failsWithMessage (equalTo ("id\n Expected: 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\n Expected: 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\n Unexpected: 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) ; []\n Unexpected: 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]\n Expected: a JSON object\n but none found\n ; " +
95102 "[id=5]\n Unexpected: a JSON object\n " )));
103+ assertEquals (result .getFieldMissing ().size (), 1 );
104+ assertEquals (result .getFieldUnexpected ().size (), 1 );
96105 }
97106
98107 @ Test
0 commit comments