/** * Compares JSONObject provided to the expected JSONObject, and returns the results of the comparison. * * @param expected Expected JSONObject * @param actual JSONObject to compare * @throws JSONException JSON parsing error */ @Override public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) throws JSONException { JSONCompareResult result = new JSONCompareResult(); compareJSON("", expected, actual, result); return result; }
/** * Compares JSONArray provided to the expected JSONArray, and returns the results of the comparison. * * @param expected Expected JSONArray * @param actual JSONArray to compare * @throws JSONException JSON parsing error */ @Override public final JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) throws JSONException { JSONCompareResult result = new JSONCompareResult(); compareJSONArray("", expected, actual, result); return result; }
/** * Compares {@link JSONString} provided to the expected {@code JSONString}, checking that the * {@link org.json.JSONString#toJSONString()} are equal. * * @param expected Expected {@code JSONstring} * @param actual {@code JSONstring} to compare * @return result of the comparison */ public static JSONCompareResult compareJson(final JSONString expected, final JSONString actual) { final JSONCompareResult result = new JSONCompareResult(); final String expectedJson = expected.toJSONString(); final String actualJson = actual.toJSONString(); if (!expectedJson.equals(actualJson)) { result.fail(""); } return result; }
/** * Compares JSON string provided to the expected JSON string using provided comparator, and returns the results of * the comparison. * @param expectedStr Expected JSON string * @param actualStr JSON string to compare * @param comparator Comparator to use * @return result of the comparison * @throws JSONException JSON parsing error * @throws IllegalArgumentException when type of expectedStr doesn't match the type of actualStr */ public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { Object expected = JSONParser.parseJSON(expectedStr); Object actual = JSONParser.parseJSON(actualStr); if ((expected instanceof JSONObject) && (actual instanceof JSONObject)) { return compareJSON((JSONObject) expected, (JSONObject) actual, comparator); } else if ((expected instanceof JSONArray) && (actual instanceof JSONArray)) { return compareJSON((JSONArray)expected, (JSONArray)actual, comparator); } else if (expected instanceof JSONString && actual instanceof JSONString) { return compareJson((JSONString) expected, (JSONString) actual); } else if (expected instanceof JSONObject) { return new JSONCompareResult().fail("", expected, actual); } else { return new JSONCompareResult().fail("", expected, actual); } }
/** * Compares JSONObject provided to the expected JSONObject, and returns the results of the comparison. * * @param expected Expected JSONObject * @param actual JSONObject to compare * @throws JSONException JSON parsing error */ @Override public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) throws JSONException { JSONCompareResult result = new JSONCompareResult(); compareJSON("", expected, actual, result); return result; }
/** * Compares JSONArray provided to the expected JSONArray, and returns the results of the comparison. * * @param expected Expected JSONArray * @param actual JSONArray to compare * @throws JSONException JSON parsing error */ @Override public final JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) throws JSONException { JSONCompareResult result = new JSONCompareResult(); compareJSONArray("", expected, actual, result); return result; }
/** * Compares {@link JSONString} provided to the expected {@code JSONString}, checking that the * {@link org.json.JSONString#toJSONString()} are equal. * * @param expected Expected {@code JSONstring} * @param actual {@code JSONstring} to compare * @return result of the comparison */ public static JSONCompareResult compareJson(final JSONString expected, final JSONString actual) { final JSONCompareResult result = new JSONCompareResult(); final String expectedJson = expected.toJSONString(); final String actualJson = actual.toJSONString(); if (!expectedJson.equals(actualJson)) { result.fail(""); } return result; }
/** * Compares JSON string provided to the expected JSON string using provided comparator, and returns the results of * the comparison. * @param expectedStr Expected JSON string * @param actualStr JSON string to compare * @param comparator Comparator to use * @return result of the comparison * @throws JSONException JSON parsing error * @throws IllegalArgumentException when type of expectedStr doesn't match the type of actualStr */ public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { Object expected = JSONParser.parseJSON(expectedStr); Object actual = JSONParser.parseJSON(actualStr); if ((expected instanceof JSONObject) && (actual instanceof JSONObject)) { return compareJSON((JSONObject) expected, (JSONObject) actual, comparator); } else if ((expected instanceof JSONArray) && (actual instanceof JSONArray)) { return compareJSON((JSONArray)expected, (JSONArray)actual, comparator); } else if (expected instanceof JSONString && actual instanceof JSONString) { return compareJson((JSONString) expected, (JSONString) actual); } else if (expected instanceof JSONObject) { return new JSONCompareResult().fail("", expected, actual); } else { return new JSONCompareResult().fail("", expected, actual); } }
private JSONCompareResult compareForNull(CharSequence expectedJson) { JSONCompareResult result = new JSONCompareResult(); result.passed(); if (expectedJson != null) { result.fail("Expected null JSON"); } return result; }
JSONCompareResult tmpResult = new JSONCompareResult(); compareValues(prefix + "[" + i + "]", expectedValue, actualValue, tmpResult); if (tmpResult.passed()) { JSONCompareResult tmpResult = new JSONCompareResult(); super.compareJSON(prefix + "[" + i + "]", expectedValue, actValueMostlySimilar, tmpResult); result.fail(tmpResult.getMessage());