|
21 | 21 | import static org.skyscreamer.jsonassert.JSONCompare.compareJSON; |
22 | 22 | import static org.skyscreamer.jsonassert.JSONCompareMode.LENIENT; |
23 | 23 | import static org.skyscreamer.jsonassert.JSONCompareMode.NON_EXTENSIBLE; |
| 24 | +import static org.skyscreamer.jsonassert.JSONCompareMode.STRICT; |
24 | 25 |
|
25 | 26 | import org.hamcrest.Description; |
26 | 27 | import org.hamcrest.Matcher; |
@@ -158,6 +159,32 @@ public void reportsUnmatchedJSONArrayWhereExpectedContainsJSONObjectWithUniqueKe |
158 | 159 | assertThat(result, failsWithMessage(equalTo("[0] Could not find match for element {\"id\":3}"))); |
159 | 160 | } |
160 | 161 |
|
| 162 | + @Test |
| 163 | + public void reportsUnmatchedJSONArrayWhereExpectedContainsNonnullIntegerButActualContainsNullElement() throws JSONException { |
| 164 | + JSONCompareResult result = compareJSON("[ 3 ]", "[ null ]", LENIENT); |
| 165 | + assertThat(result, failsWithMessage(equalTo("[]\nExpected: 3\n but none found\n ; " + |
| 166 | + "[]\nUnexpected: null\n"))); |
| 167 | + } |
| 168 | + |
| 169 | + @Test |
| 170 | + public void reportsUnmatchedJSONArrayWhereExpectedContainsNullElementButActualContainsNonnullInteger() throws JSONException { |
| 171 | + JSONCompareResult result = compareJSON("[ null ]", "[ 3 ]", LENIENT); |
| 172 | + assertThat(result, failsWithMessage(equalTo("[]\nExpected: null\n but none found\n ; " + |
| 173 | + "[]\nUnexpected: 3\n"))); |
| 174 | + } |
| 175 | + |
| 176 | + @Test |
| 177 | + public void reportsStrictUnmatchedJSONArrayWhereExpectedContainsNonnullIntegerButActualContainsNullElement() throws JSONException { |
| 178 | + JSONCompareResult result = compareJSON("[ 3 ]", "[ null ]", STRICT); |
| 179 | + assertThat(result, failsWithMessage(equalTo("[0]\nExpected: 3\n got: null\n"))); |
| 180 | + } |
| 181 | + |
| 182 | + @Test |
| 183 | + public void reportsStrictUnmatchedJSONArrayWhereExpectedContainsNullButActualContainsNonnullInteger() throws JSONException { |
| 184 | + JSONCompareResult result = compareJSON("[ null ]", "[ 3 ]", STRICT); |
| 185 | + assertThat(result, failsWithMessage(equalTo("[0]\nExpected: null\n got: 3\n"))); |
| 186 | + } |
| 187 | + |
161 | 188 | private Matcher<JSONCompareResult> failsWithMessage(final Matcher<String> expectedMessage) { |
162 | 189 | return new TypeSafeMatcher<JSONCompareResult>() { |
163 | 190 | @Override |
|
0 commit comments