@@ -52,6 +52,22 @@ public static void assertEquals(String expectedStr, JSONObject actual, boolean s
5252 assertEquals (expectedStr , actual , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
5353 }
5454
55+ /**
56+ * Asserts that the JSONObject provided does not match the expected string. If it is it throws an
57+ * {@link AssertionError}.
58+ *
59+ * @see #assertEquals(String JSONObject, boolean)
60+ *
61+ * @param expectedStr Expected JSON string
62+ * @param actual JSONObject to compare
63+ * @param strict Enables strict checking
64+ * @throws JSONException
65+ */
66+ public static void assertNotEquals (String expectedStr , JSONObject actual , boolean strict )
67+ throws JSONException {
68+ assertNotEquals (expectedStr , actual , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
69+ }
70+
5571 /**
5672 * Asserts that the JSONObject provided matches the expected string. If it isn't it throws an
5773 * {@link AssertionError}.
@@ -72,6 +88,28 @@ public static void assertEquals(String expectedStr, JSONObject actual, JSONCompa
7288 }
7389 }
7490
91+ /**
92+ * Asserts that the JSONObject provided does not match the expected string. If it is it throws an
93+ * {@link AssertionError}.
94+ *
95+ * @see #assertEquals(String, JSONObject, JSONCompareMode)
96+ *
97+ * @param expectedStr Expected JSON string
98+ * @param actual JSONObject to compare
99+ * @param compareMode Specifies which comparison mode to use
100+ * @throws JSONException
101+ */
102+ public static void assertNotEquals (String expectedStr , JSONObject actual , JSONCompareMode compareMode )
103+ throws JSONException {
104+ Object expected = JSONParser .parseJSON (expectedStr );
105+ if (expected instanceof JSONObject ) {
106+ assertNotEquals ((JSONObject ) expected , actual , compareMode );
107+ }
108+ else {
109+ throw new AssertionError ("Expecting a JSON array, but passing in a JSON object" );
110+ }
111+ }
112+
75113 /**
76114 * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
77115 * {@link AssertionError}.
@@ -86,6 +124,20 @@ public static void assertEquals(String expectedStr, JSONArray actual, boolean st
86124 assertEquals (expectedStr , actual , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
87125 }
88126
127+ /**
128+ * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
129+ * {@link AssertionError}.
130+ *
131+ * @param expectedStr Expected JSON string
132+ * @param actual JSONArray to compare
133+ * @param strict Enables strict checking
134+ * @throws JSONException
135+ */
136+ public static void assertNotEquals (String expectedStr , JSONArray actual , boolean strict )
137+ throws JSONException {
138+ assertNotEquals (expectedStr , actual , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
139+ }
140+
89141 /**
90142 * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
91143 * {@link AssertionError}.
@@ -99,7 +151,27 @@ public static void assertEquals(String expectedStr, JSONArray actual, JSONCompar
99151 throws JSONException {
100152 Object expected = JSONParser .parseJSON (expectedStr );
101153 if (expected instanceof JSONArray ) {
102- assertEquals ((JSONArray )expected , actual , compareMode );
154+ assertEquals ((JSONArray ) expected , actual , compareMode );
155+ }
156+ else {
157+ throw new AssertionError ("Expecting a JSON object, but passing in a JSON array" );
158+ }
159+ }
160+
161+ /**
162+ * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
163+ * {@link AssertionError}.
164+ *
165+ * @param expectedStr Expected JSON string
166+ * @param actual JSONArray to compare
167+ * @param compareMode Specifies which comparison mode to use
168+ * @throws JSONException
169+ */
170+ public static void assertNotEquals (String expectedStr , JSONArray actual , JSONCompareMode compareMode )
171+ throws JSONException {
172+ Object expected = JSONParser .parseJSON (expectedStr );
173+ if (expected instanceof JSONArray ) {
174+ assertNotEquals ((JSONArray ) expected , actual , compareMode );
103175 }
104176 else {
105177 throw new AssertionError ("Expecting a JSON object, but passing in a JSON array" );
@@ -120,6 +192,20 @@ public static void assertEquals(String expectedStr, String actualStr, boolean st
120192 assertEquals (expectedStr , actualStr , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
121193 }
122194
195+ /**
196+ * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
197+ * {@link AssertionError}.
198+ *
199+ * @param expectedStr Expected JSON string
200+ * @param actualStr String to compare
201+ * @param strict Enables strict checking
202+ * @throws JSONException
203+ */
204+ public static void assertNotEquals (String expectedStr , String actualStr , boolean strict )
205+ throws JSONException {
206+ assertNotEquals (expectedStr , actualStr , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
207+ }
208+
123209 /**
124210 * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
125211 * {@link AssertionError}.
@@ -137,6 +223,23 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar
137223 }
138224 }
139225
226+ /**
227+ * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
228+ * {@link AssertionError}.
229+ *
230+ * @param expectedStr Expected JSON string
231+ * @param actualStr String to compare
232+ * @param compareMode Specifies which comparison mode to use
233+ * @throws JSONException
234+ */
235+ public static void assertNotEquals (String expectedStr , String actualStr , JSONCompareMode compareMode )
236+ throws JSONException {
237+ JSONCompareResult result = JSONCompare .compareJSON (expectedStr , actualStr , compareMode );
238+ if (result .passed ()) {
239+ throw new AssertionError (result .getMessage ());
240+ }
241+ }
242+
140243 /**
141244 * Asserts that the json string provided matches the expected string. If it isn't it throws an
142245 * {@link AssertionError}.
@@ -154,6 +257,23 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar
154257 }
155258 }
156259
260+ /**
261+ * Asserts that the json string provided does not match the expected string. If it is it throws an
262+ * {@link AssertionError}.
263+ *
264+ * @param expectedStr Expected JSON string
265+ * @param actualStr String to compare
266+ * @param comparator Comparator
267+ * @throws JSONException
268+ */
269+ public static void assertNotEquals (String expectedStr , String actualStr , JSONComparator comparator )
270+ throws JSONException {
271+ JSONCompareResult result = JSONCompare .compareJSON (expectedStr , actualStr , comparator );
272+ if (result .passed ()) {
273+ throw new AssertionError (result .getMessage ());
274+ }
275+ }
276+
157277 /**
158278 * Asserts that the JSONObject provided matches the expected JSONObject. If it isn't it throws an
159279 * {@link AssertionError}.
@@ -168,6 +288,20 @@ public static void assertEquals(JSONObject expected, JSONObject actual, boolean
168288 assertEquals (expected , actual , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
169289 }
170290
291+ /**
292+ * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an
293+ * {@link AssertionError}.
294+ *
295+ * @param expected Expected JSONObject
296+ * @param actual JSONObject to compare
297+ * @param strict Enables strict checking
298+ * @throws JSONException
299+ */
300+ public static void assertNotEquals (JSONObject expected , JSONObject actual , boolean strict )
301+ throws JSONException {
302+ assertNotEquals (expected , actual , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
303+ }
304+
171305 /**
172306 * Asserts that the JSONObject provided matches the expected JSONObject. If it isn't it throws an
173307 * {@link AssertionError}.
@@ -186,6 +320,24 @@ public static void assertEquals(JSONObject expected, JSONObject actual, JSONComp
186320 }
187321 }
188322
323+ /**
324+ * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an
325+ * {@link AssertionError}.
326+ *
327+ * @param expected Expected JSONObject
328+ * @param actual JSONObject to compare
329+ * @param compareMode Specifies which comparison mode to use
330+ * @throws JSONException
331+ */
332+ public static void assertNotEquals (JSONObject expected , JSONObject actual , JSONCompareMode compareMode )
333+ throws JSONException
334+ {
335+ JSONCompareResult result = JSONCompare .compareJSON (expected , actual , compareMode );
336+ if (result .passed ()) {
337+ throw new AssertionError (result .getMessage ());
338+ }
339+ }
340+
189341 /**
190342 * Asserts that the JSONArray provided matches the expected JSONArray. If it isn't it throws an
191343 * {@link AssertionError}.
@@ -200,6 +352,20 @@ public static void assertEquals(JSONArray expected, JSONArray actual, boolean st
200352 assertEquals (expected , actual , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
201353 }
202354
355+ /**
356+ * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an
357+ * {@link AssertionError}.
358+ *
359+ * @param expected Expected JSONArray
360+ * @param actual JSONArray to compare
361+ * @param strict Enables strict checking
362+ * @throws JSONException
363+ */
364+ public static void assertNotEquals (JSONArray expected , JSONArray actual , boolean strict )
365+ throws JSONException {
366+ assertNotEquals (expected , actual , strict ? JSONCompareMode .STRICT : JSONCompareMode .LENIENT );
367+ }
368+
203369 /**
204370 * Asserts that the JSONArray provided matches the expected JSONArray. If it isn't it throws an
205371 * {@link AssertionError}.
@@ -216,4 +382,21 @@ public static void assertEquals(JSONArray expected, JSONArray actual, JSONCompar
216382 throw new AssertionError (result .getMessage ());
217383 }
218384 }
385+
386+ /**
387+ * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an
388+ * {@link AssertionError}.
389+ *
390+ * @param expected Expected JSONArray
391+ * @param actual JSONArray to compare
392+ * @param compareMode Specifies which comparison mode to use
393+ * @throws JSONException
394+ */
395+ public static void assertNotEquals (JSONArray expected , JSONArray actual , JSONCompareMode compareMode )
396+ throws JSONException {
397+ JSONCompareResult result = JSONCompare .compareJSON (expected , actual , compareMode );
398+ if (result .passed ()) {
399+ throw new AssertionError (result .getMessage ());
400+ }
401+ }
219402}
0 commit comments