Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience methods for JSONObject comparison using JSONComparator #90

Merged
merged 1 commit into from
Nov 18, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/main/java/org/skyscreamer/jsonassert/JSONAssert.java
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,70 @@ public static void assertNotEquals(String message, String expectedStr, String ac
}
}

/**
* 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 comparator Comparator
* @throws JSONException JSON parsing error
*/
public static void assertEquals(JSONObject expected, JSONObject actual, JSONComparator comparator)
throws JSONException {
assertEquals("", expected, actual, comparator);
}

/**
* 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 comparator Comparator
* @throws JSONException JSON parsing error
*/
public static void assertEquals(String message, JSONObject expected, JSONObject actual, JSONComparator comparator)
throws JSONException {
JSONCompareResult result = JSONCompare.compareJSON(expected, actual, comparator);
if (result.failed()) {
throw new AssertionError(getCombinedMessage(message, result.getMessage()));
}
}

/**
* 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 comparator Comparator
* @throws JSONException JSON parsing error
*/
public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONComparator comparator)
throws JSONException {
assertNotEquals("", expected, actual, comparator);
}

/**
* 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 comparator Comparator
* @throws JSONException JSON parsing error
*/
public static void assertNotEquals(String message, JSONObject expected, JSONObject actual, JSONComparator comparator)
throws JSONException {
JSONCompareResult result = JSONCompare.compareJSON(expected, actual, comparator);
if (result.passed()) {
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}.
Expand Down