Package uk.co.datumedge.hamcrest.json
Class SameJSONAs<T>
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeDiagnosingMatcher<T>
uk.co.datumedge.hamcrest.json.SameJSONAs<T>
- Type Parameters:
T- the type of the JSON document. This is typicallyJSONObject,JSONArrayorString.
- All Implemented Interfaces:
org.hamcrest.Matcher<T>,org.hamcrest.SelfDescribing
public final class SameJSONAs<T>
extends org.hamcrest.TypeSafeDiagnosingMatcher<T>
Matcher that asserts that one JSON document is the same as another.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates a matcher that allows any element ordering within JSON arrays.Creates a matcher that allows fields not present in the expected JSON document.voiddescribeTo(org.hamcrest.Description description) protected booleanmatchesSafely(T actual, org.hamcrest.Description mismatchDescription) static SameJSONAs<org.json.JSONArray>sameJSONArrayAs(org.json.JSONArray expected) Creates a matcher that comparesJSONArrays.static SameJSONAs<? super org.json.JSONArray>sameJSONArrayAs(org.json.JSONArray expected, JSONModalComparator<org.json.JSONArray> comparator) static SameJSONAs<? super String>sameJSONAs(String expected) Creates a matcher that comparesJSONObjects orJSONArrays represented asStrings.static SameJSONAs<? super String>sameJSONAs(String expected, JSONModalComparator<String> comparator) static SameJSONAs<org.json.JSONObject>sameJSONObjectAs(org.json.JSONObject expected) Creates a matcher that comparesJSONObjects.static SameJSONAs<org.json.JSONObject>sameJSONObjectAs(org.json.JSONObject expected, JSONModalComparator<org.json.JSONObject> comparator) Methods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher
describeMismatch, matchesMethods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
-
Constructor Details
-
SameJSONAs
-
-
Method Details
-
describeTo
public void describeTo(org.hamcrest.Description description) -
matchesSafely
- Specified by:
matchesSafelyin classorg.hamcrest.TypeSafeDiagnosingMatcher<T>
-
allowingAnyArrayOrdering
Creates a matcher that allows any element ordering within JSON arrays. For example,{"fib":[0,1,1,2,3]}will match{"fib":[3,1,0,2,1]}.- Returns:
- the configured matcher
-
allowingExtraUnexpectedFields
Creates a matcher that allows fields not present in the expected JSON document. For example, if the expected document is{ "name" : "John Smith", "address" : { "street" : "29 Acacia Road" } }then the following document will match:{ "name" : "John Smith", "age" : 34, "address" : { "street" : "29 Acacia Road", "city" : "Huddersfield" } }All array elements must exist in both documents, so the expected document[ { "name" : "John Smith" } ]will not match the actual document[ { "name" : "John Smith" }, { "name" : "Bob Jones" } ]- Returns:
- the configured matcher
-
sameJSONObjectAs
Creates a matcher that comparesJSONObjects.- Parameters:
expected- the expectedJSONObjectinstance- Returns:
- the
Matcherinstance
-
sameJSONObjectAs
public static SameJSONAs<org.json.JSONObject> sameJSONObjectAs(org.json.JSONObject expected, JSONModalComparator<org.json.JSONObject> comparator) -
sameJSONArrayAs
Creates a matcher that comparesJSONArrays.- Parameters:
expected- the expectedJSONArrayinstance- Returns:
- the
Matcherinstance
-
sameJSONArrayAs
public static SameJSONAs<? super org.json.JSONArray> sameJSONArrayAs(org.json.JSONArray expected, JSONModalComparator<org.json.JSONArray> comparator) -
sameJSONAs
Creates a matcher that comparesJSONObjects orJSONArrays represented asStrings.- Parameters:
expected- the expected JSON document- Returns:
- the
Matcherinstance
-
sameJSONAs
public static SameJSONAs<? super String> sameJSONAs(String expected, JSONModalComparator<String> comparator)
-