/** * Parse the expected and actual strings as JSON and assert the two * are "similar" - i.e. they contain the same 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 assertJsonEqual(String expected, String actual, boolean strict) throws Exception { JSONAssert.assertEquals(expected, actual, strict); }
/** * 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 matches the expected string. If it isn't 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 compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, String actualStr, JSONCompareMode compareMode) throws JSONException { if (expectedStr==actualStr) return; if (expectedStr==null){ throw new AssertionError("Expected string is null."); }else if (actualStr==null){ throw new AssertionError("Actual string is null."); } JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, compareMode); if (result.failed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); } }
/** * Asserts that the json string provided matches the expected string. If it isn't 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 comparator Comparator * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, comparator); if (result.failed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); } }
/** * Asserts that the JSONObject provided matches the expected JSONObject. If it isn't 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 assertEquals(JSONObject expected, JSONObject actual, JSONCompareMode compareMode) throws JSONException { assertEquals("", expected, actual, compareMode); }
/** * 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 compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, JSONObject expected, JSONObject actual, JSONCompareMode compareMode) throws JSONException { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); if (result.passed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); } }
/** * Asserts that the JSONArray provided matches the expected string. If it isn't 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 assertEquals(String expectedStr, String actualStr, boolean strict) throws JSONException { assertEquals(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 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 matches the expected JSONObject. If it isn't 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 compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertEquals(String message, JSONObject expected, JSONObject actual, JSONCompareMode compareMode) throws JSONException { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); if (result.failed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); } }
/** * Asserts that the JSONArray provided matches the expected JSONArray. If it isn't 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 assertEquals(JSONArray expected, JSONArray actual, boolean strict) throws JSONException { assertEquals("", expected, 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 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 matches the expected JSONArray. If it isn't 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 compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertEquals(String message, JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); if (result.failed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); } }
/** * Asserts that the JSONArray provided matches the expected JSONArray. If it isn't 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 assertEquals(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { assertEquals("", 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 json string 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 comparator Comparator * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, comparator); if (result.passed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); } }
/** * Asserts that the JSONObject provided matches the expected string. If it isn't it throws an * {@link AssertionError}. * * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking * @throws JSONException JSON parsing error */ public static void assertEquals(String expectedStr, JSONObject actual, boolean strict) throws JSONException { assertEquals(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 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 compareMode Specifies which comparison mode to use * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); if (result.passed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); } }
/** * Asserts that the JSONArray provided matches the expected string. If it isn't 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 assertEquals(String expectedStr, JSONArray actual, boolean strict) throws JSONException { assertEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); }