/** * Parse the expected and actual strings as JSON and assert the two * are "not similar" - i.e. they contain different attribute-value pairs * regardless of formatting. * <p>Can compare in two modes, depending on {@code strict} parameter value: * <ul> * <li>{@code true}: strict checking. Not extensible, and strict array ordering.</li> * <li>{@code false}: lenient checking. Extensible, and non-strict array ordering.</li> * </ul> * @param expected the expected JSON content * @param actual the actual JSON content * @param strict enables strict checking * @since 4.2 */ public void assertJsonNotEqual(String expected, String actual, boolean strict) throws Exception { JSONAssert.assertNotEquals(expected, actual, strict); }
/** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, JSONArray actual, boolean strict) throws JSONException { assertNotEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an * {@link AssertionError}. * * @param message Error message to be displayed in case of assertion failure * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, JSONObject expected, JSONObject actual, boolean strict) throws JSONException { assertNotEquals(message, expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @param expectedStr Expected JSON string * @param actualStr String to compare * @param compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, String actualStr, JSONCompareMode compareMode) throws JSONException { assertNotEquals("", expectedStr, actualStr, compareMode); }
/** * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an * {@link AssertionError}. * * @param expected Expected JSONObject * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONCompareMode compareMode) throws JSONException { assertNotEquals("", expected, actual, compareMode); }
/** * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an * {@link AssertionError}. * * @param message Error message to be displayed in case of assertion failure * @param expected Expected JSONArray * @param actual JSONArray to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, JSONArray expected, JSONArray actual, boolean strict) throws JSONException { assertNotEquals(message, expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @param expectedStr Expected JSON string * @param actualStr String to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, String actualStr, boolean strict) throws JSONException { assertNotEquals(expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the json string provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @param expectedStr Expected JSON string * @param actualStr String to compare * @param comparator Comparator * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { assertNotEquals("", expectedStr, actualStr, comparator); }
/** * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an * {@link AssertionError}. * * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(JSONObject expected, JSONObject actual, boolean strict) throws JSONException { assertNotEquals(expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an * {@link AssertionError}. * * @param expected Expected JSONArray * @param actual JSONArray to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean strict) throws JSONException { assertNotEquals(expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an * {@link AssertionError}. * * @param expected Expected JSONArray * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { assertNotEquals("", expected, actual, compareMode); }
/** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @param message Error message to be displayed in case of assertion failure * @param expectedStr Expected JSON string * @param actualStr String to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, String actualStr, boolean strict) throws JSONException { assertNotEquals(message, expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @param message Error message to be displayed in case of assertion failure * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, JSONArray actual, boolean strict) throws JSONException { assertNotEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONObject provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @see #assertEquals(String, JSONObject, boolean) * * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, JSONObject actual, boolean strict) throws JSONException { assertNotEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONObject provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @see #assertEquals(String, JSONObject, JSONCompareMode) * * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) throws JSONException { assertNotEquals("", expectedStr, actual, compareMode); }
/** * Asserts that the JSONObject provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @see #assertEquals(String, JSONObject, boolean) * * @param message Error message to be displayed in case of assertion failure * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, JSONObject actual, boolean strict) throws JSONException { assertNotEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }
/** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCompareMode compareMode) throws JSONException { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONArray) { assertNotEquals((JSONArray) expected, actual, compareMode); } else { throw new AssertionError("Expecting a JSON object, but passing in a JSON array"); } }
/** * Asserts that the JSONObject provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @see #assertEquals(String, JSONObject, JSONCompareMode) * * @param message Error message to be displayed in case of assertion failure * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, JSONObject actual, JSONCompareMode compareMode) throws JSONException { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONObject) { assertNotEquals(message, (JSONObject) expected, actual, compareMode); } else { throw new AssertionError("Expecting a JSON array, but passing in a JSON object"); } }
/** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an * {@link AssertionError}. * * @param message Error message to be displayed in case of assertion failure * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, JSONArray actual, JSONCompareMode compareMode) throws JSONException { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONArray) { assertNotEquals(message, (JSONArray) expected, actual, compareMode); } else { throw new AssertionError("Expecting a JSON object, but passing in a JSON array"); } }
private String removeNode(String json, ObjectMapper mapper, String toRemove) throws Exception { ObjectNode node = mapper.getFactory().createParser(json).readValueAsTree(); node.remove(toRemove); String result = mapper.writeValueAsString(node); JSONAssert.assertNotEquals(json, result, false); return result; }