Skip to content

Commit

Permalink
Merge pull request #90 from jakob-o/feature/convenience-methods
Browse files Browse the repository at this point in the history
Convenience methods for JSONObject comparison using  JSONComparator
  • Loading branch information
carterpage authored Nov 18, 2020
2 parents d889f22 + b83b7ad commit 523009b
Showing 1 changed file with 64 additions and 0 deletions.
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

0 comments on commit 523009b

Please sign in to comment.