From 78e30a08621d83aea3e3f0a6023a565478744135 Mon Sep 17 00:00:00 2001 From: Duncan Mackinder Date: Tue, 11 Feb 2014 17:00:10 +0000 Subject: [PATCH 01/84] Fix & improve ArrayValueMatcher JavaDoc Fix final JavaDoc example and add new example showing how to verify every array element using a custom comparator --- .../jsonassert/ArrayValueMatcher.java | 22 ++++++++++++++++++- .../jsonassert/ArrayValueMatcherTest.java | 18 +++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java index 112a36eb..1ffd7a5a 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java @@ -52,6 +52,25 @@ * JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); * * + *

To verify that the 'id' attribute of every element of array 'a' matches regular expression '\d+'. This requires a custom comparator to specify regular expression to be used to validate each array element, hence the array of Customization instances:

+ * + * + * // get length of array we will verify
+ * int aLength = ((JSONArray)((JSONObject)JSONParser.parseJSON(ARRAY_OF_JSONOBJECTS)).get("a")).length();
+ * // create array of customizations one for each array element
+ * RegularExpressionValueMatcher<Object> regExValueMatcher = new RegularExpressionValueMatcher<Object>("\\d+"); // matches one or more digits
+ * Customization[] customizations = new Customization[aLength];
+ * for (int i=0; i<aLength; i++) {
+ *   String contextPath = "a["+i+"].id";
+ *   customizations[i] = new Customization(contextPath, regExValueMatcher);
+ * }
+ * CustomComparator regExComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, customizations);
+ * ArrayValueMatcher<Object> regExArrayValueMatcher = new ArrayValueMatcher<Object>(regExComparator);
+ * Customization regExArrayValueCustomization = new Customization("a", regExArrayValueMatcher);
+ * CustomComparator regExCustomArrayValueComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, new Customization[] { regExArrayValueCustomization });
+ * JSONAssert.assertEquals("{a:[{id:X}]}", ARRAY_OF_JSONOBJECTS, regExCustomArrayValueComparator);
+ *
+ * *

To verify that the 'background' attribute of every element of array 'a' alternates between 'white' and 'grey' starting with first element 'background' being 'white':

* * @@ -79,7 +98,8 @@ *

To verify that the second elements of JSON array 'a' is a JSON array whose first element has the value 9:

* * - * Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher<Object>(comparator, 0));
+ * JSONComparator innerComparator = new DefaultComparator(JSONCompareMode.LENIENT);
+ * Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher<Object>(innerComparator, 0));
* JSONComparator comparator = new CustomComparator(JSONCompareMode.LENIENT, innerCustomization);
* Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 1));
* JSONAssert.assertEquals("{a:[[9]]}", ARRAY_OF_JSONARRAYS, new CustomComparator(JSONCompareMode.LENIENT, customization)); diff --git a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java index f62dee34..8c7b97da 100644 --- a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java @@ -209,6 +209,24 @@ public void verifyTypeAttributeOfEveryArrayElementMatchesRow() throws JSONExcept JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); } + @Test + public void verifyEveryArrayElementWithCustomComparator() throws JSONException { + // get length of array we will verify + int aLength = ((JSONArray)((JSONObject)JSONParser.parseJSON(ARRAY_OF_JSONOBJECTS)).get("a")).length(); + // create array of customizations one for each array element + RegularExpressionValueMatcher regExValueMatcher = new RegularExpressionValueMatcher("\\d+"); // matches one or more digits + Customization[] customizations = new Customization[aLength]; + for (int i=0; i regExArrayValueMatcher = new ArrayValueMatcher(regExComparator); + Customization regExArrayValueCustomization = new Customization("a", regExArrayValueMatcher); + CustomComparator regExCustomArrayValueComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, new Customization[] { regExArrayValueCustomization }); + JSONAssert.assertEquals("{a:[{id:X}]}", ARRAY_OF_JSONOBJECTS, regExCustomArrayValueComparator); + } + @Test public void verifyBackgroundAttributesOfEveryArrayElementAlternateBetweenWhiteAndGrey() throws JSONException { JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT); From 1c87ae208ece96f8b3b37fb84cf3396c542f7bcf Mon Sep 17 00:00:00 2001 From: Auke van Leeuwen Date: Fri, 17 Oct 2014 11:44:55 +0200 Subject: [PATCH 02/84] Update URL in the pom.xml Happened to notice this while looking at the dependencies of the hamcrest-json: http://www.datumedge.co.uk/hamcrest-json/dependencies.html. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 50dc2183..3c2e04b5 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ JSONassert A library to develop RESTful but flexible APIs - http://github.com/skyscreamer/yoga + https://github.com/skyscreamer/JSONassert From 7c9f6be62f19611167ba9e128ce501ce52994482 Mon Sep 17 00:00:00 2001 From: riccorazza Date: Wed, 24 Jun 2015 13:38:13 +0200 Subject: [PATCH 03/84] Update JSONCompareResult.java Improved classe adding 2 new lists for missing and unexpected fileds. --- .../jsonassert/JSONCompareResult.java | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java index 2b772ac0..390d70f4 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java @@ -17,6 +17,8 @@ public class JSONCompareResult { private Object _expected; private Object _actual; private final List _fieldFailures = new ArrayList(); + private final List _fieldMissing = new ArrayList(); + private final List _fieldUnexpected = new ArrayList(); /** * Default constructor. @@ -60,6 +62,20 @@ public String getMessage() { public List getFieldFailures() { return Collections.unmodifiableList(_fieldFailures); } + + /** + * Get the list of missed on field comparisons + */ + public List getFieldMissing() { + return Collections.unmodifiableList(_fieldMissing); + } + + /** + * Get the list of failures on field comparisons + */ + public List getFieldUnexpected() { + return Collections.unmodifiableList(_fieldUnexpected); + } /** * Actual field value @@ -69,7 +85,8 @@ public List getFieldFailures() { * particular field * @deprecated Superseded by {@link #getFieldFailures()} */ - public Object getActual() { + @Deprecated + public Object getActual() { return _actual; } @@ -81,7 +98,8 @@ public Object getActual() { * particular field * @deprecated Superseded by {@link #getFieldFailures()} */ - public Object getExpected() { + @Deprecated + public Object getExpected() { return _expected; } @@ -91,6 +109,20 @@ public Object getExpected() { public boolean isFailureOnField() { return !_fieldFailures.isEmpty(); } + + /** + * Check if comparison failed with missing on any particular fields + */ + public boolean isMissingOnField() { + return !_fieldMissing.isEmpty(); + } + + /** + * Check if comparison failed with unexpected on any particular fields + */ + public boolean isUnexpectedOnField() { + return !_fieldUnexpected.isEmpty(); + } /** * Dot-separated path the the field that failed comparison @@ -99,7 +131,8 @@ public boolean isFailureOnField() { * not fail on a particular field * @deprecated Superseded by {@link #getFieldFailures()} */ - public String getField() { + @Deprecated + public String getField() { return _field; } @@ -147,6 +180,7 @@ private String formatFailureMessage(String field, Object expected, Object actual } public JSONCompareResult missing(String field, Object expected) { + _fieldMissing.add(new FieldComparisonFailure(field, expected, null)); fail(formatMissing(field, expected)); return this; } @@ -159,6 +193,7 @@ private String formatMissing(String field, Object expected) { } public JSONCompareResult unexpected(String field, Object value) { + _fieldUnexpected.add(new FieldComparisonFailure(field, null, value)); fail(formatUnexpected(field, value)); return this; } From 3ab86af6ab2a26ca93b36403a75d03c31e0b89d3 Mon Sep 17 00:00:00 2001 From: riccorazza Date: Mon, 20 Jul 2015 12:27:35 +0200 Subject: [PATCH 04/84] Update JSONCompareTest.java --- .../java/org/skyscreamer/jsonassert/JSONCompareTest.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java index c4727598..73531d79 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java @@ -1,6 +1,7 @@ package org.skyscreamer.jsonassert; import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.skyscreamer.jsonassert.JSONCompare.compareJSON; @@ -32,18 +33,22 @@ public void reportsArraysOfUnequalLength() throws JSONException { public void reportsArrayMissingExpectedElement() throws JSONException { JSONCompareResult result = compareJSON("[4]", "[7]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]\nExpected: 4\n but none found\n ; []\nUnexpected: 7\n"))); + assertEquals(result.getFieldMissing().size(), 1); + assertEquals(result.getFieldUnexpected().size(), 1); } @Test public void reportsMismatchedFieldValues() throws JSONException { JSONCompareResult result = compareJSON("{\"id\": 3}", "{\"id\": 5}", LENIENT); assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n"))); + assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n"))); } @Test public void reportsMissingField() throws JSONException { JSONCompareResult result = compareJSON("{\"obj\": {\"id\": 3}}", "{\"obj\": {}}", LENIENT); assertThat(result, failsWithMessage(equalTo("obj\nExpected: id\n but none found\n"))); + assertEquals(result.getFieldMissing().size(), 1); } @Test @@ -74,6 +79,7 @@ public void reportsUnexpectedNonNull() throws JSONException { public void reportsUnexpectedFieldInNonExtensibleMode() throws JSONException { JSONCompareResult result = compareJSON("{\"obj\": {}}", "{\"obj\": {\"id\": 3}}", NON_EXTENSIBLE); assertThat(result, failsWithMessage(equalTo("obj\nUnexpected: id\n"))); + assertEquals(result.getFieldUnexpected().size(), 1); } @Test @@ -86,6 +92,7 @@ public void reportsMismatchedTypes() throws JSONException { public void reportsWrongSimpleValueCountInUnorderedArray() throws JSONException { JSONCompareResult result = compareJSON("[5, 5]", "[5, 7]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]: Expected 2 occurrence(s) of 5 but got 1 occurrence(s) ; []\nUnexpected: 7\n"))); + assertEquals(result.getFieldUnexpected().size(), 1); } @Test @@ -93,6 +100,8 @@ public void reportsMissingJSONObjectWithUniqueKeyInUnorderedArray() throws JSONE JSONCompareResult result = compareJSON("[{\"id\" : 3}]", "[{\"id\" : 5}]", LENIENT); assertThat(result, failsWithMessage(equalTo("[id=3]\nExpected: a JSON object\n but none found\n ; " + "[id=5]\nUnexpected: a JSON object\n"))); + assertEquals(result.getFieldMissing().size(), 1); + assertEquals(result.getFieldUnexpected().size(), 1); } @Test From 054919c5723680b2821cc2219cc3b9fb72151b5e Mon Sep 17 00:00:00 2001 From: Javier Seixas Date: Wed, 5 Aug 2015 21:54:42 +0200 Subject: [PATCH 05/84] Includes missing imports in test class --- .../java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java index 8c7b97da..fb5ca94e 100644 --- a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java @@ -6,7 +6,9 @@ import java.text.MessageFormat; +import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import org.junit.Test; import org.skyscreamer.jsonassert.comparator.ArraySizeComparator; import org.skyscreamer.jsonassert.comparator.CustomComparator; From e3a94eb4b050507ede7ec2d34a018c615a099572 Mon Sep 17 00:00:00 2001 From: riccorazza Date: Tue, 10 Nov 2015 09:37:52 +0100 Subject: [PATCH 06/84] Fixed indentation --- .../java/org/skyscreamer/jsonassert/JSONCompareResult.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java index 390d70f4..2cf7cad9 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java @@ -86,7 +86,7 @@ public List getFieldUnexpected() { * @deprecated Superseded by {@link #getFieldFailures()} */ @Deprecated - public Object getActual() { + public Object getActual() { return _actual; } @@ -99,7 +99,7 @@ public Object getActual() { * @deprecated Superseded by {@link #getFieldFailures()} */ @Deprecated - public Object getExpected() { + public Object getExpected() { return _expected; } @@ -132,7 +132,7 @@ public boolean isUnexpectedOnField() { * @deprecated Superseded by {@link #getFieldFailures()} */ @Deprecated - public String getField() { + public String getField() { return _field; } From e447e5f20df64a99f021f1e7cf4e996f59e69b1e Mon Sep 17 00:00:00 2001 From: Carter Page Date: Tue, 10 Nov 2015 14:54:18 -0800 Subject: [PATCH 07/84] Revert 797c5c16c3932aa63cec4e668144e26fbdbdc9b9 --- .../jsonassert/JSONCompareResult.java | 35 ------------------- .../jsonassert/JSONCompareTest.java | 9 ----- 2 files changed, 44 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java index 2cf7cad9..2b772ac0 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java @@ -17,8 +17,6 @@ public class JSONCompareResult { private Object _expected; private Object _actual; private final List _fieldFailures = new ArrayList(); - private final List _fieldMissing = new ArrayList(); - private final List _fieldUnexpected = new ArrayList(); /** * Default constructor. @@ -62,20 +60,6 @@ public String getMessage() { public List getFieldFailures() { return Collections.unmodifiableList(_fieldFailures); } - - /** - * Get the list of missed on field comparisons - */ - public List getFieldMissing() { - return Collections.unmodifiableList(_fieldMissing); - } - - /** - * Get the list of failures on field comparisons - */ - public List getFieldUnexpected() { - return Collections.unmodifiableList(_fieldUnexpected); - } /** * Actual field value @@ -85,7 +69,6 @@ public List getFieldUnexpected() { * particular field * @deprecated Superseded by {@link #getFieldFailures()} */ - @Deprecated public Object getActual() { return _actual; } @@ -98,7 +81,6 @@ public Object getActual() { * particular field * @deprecated Superseded by {@link #getFieldFailures()} */ - @Deprecated public Object getExpected() { return _expected; } @@ -109,20 +91,6 @@ public Object getExpected() { public boolean isFailureOnField() { return !_fieldFailures.isEmpty(); } - - /** - * Check if comparison failed with missing on any particular fields - */ - public boolean isMissingOnField() { - return !_fieldMissing.isEmpty(); - } - - /** - * Check if comparison failed with unexpected on any particular fields - */ - public boolean isUnexpectedOnField() { - return !_fieldUnexpected.isEmpty(); - } /** * Dot-separated path the the field that failed comparison @@ -131,7 +99,6 @@ public boolean isUnexpectedOnField() { * not fail on a particular field * @deprecated Superseded by {@link #getFieldFailures()} */ - @Deprecated public String getField() { return _field; } @@ -180,7 +147,6 @@ private String formatFailureMessage(String field, Object expected, Object actual } public JSONCompareResult missing(String field, Object expected) { - _fieldMissing.add(new FieldComparisonFailure(field, expected, null)); fail(formatMissing(field, expected)); return this; } @@ -193,7 +159,6 @@ private String formatMissing(String field, Object expected) { } public JSONCompareResult unexpected(String field, Object value) { - _fieldUnexpected.add(new FieldComparisonFailure(field, null, value)); fail(formatUnexpected(field, value)); return this; } diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java index 73531d79..c4727598 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java @@ -1,7 +1,6 @@ package org.skyscreamer.jsonassert; import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.skyscreamer.jsonassert.JSONCompare.compareJSON; @@ -33,22 +32,18 @@ public void reportsArraysOfUnequalLength() throws JSONException { public void reportsArrayMissingExpectedElement() throws JSONException { JSONCompareResult result = compareJSON("[4]", "[7]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]\nExpected: 4\n but none found\n ; []\nUnexpected: 7\n"))); - assertEquals(result.getFieldMissing().size(), 1); - assertEquals(result.getFieldUnexpected().size(), 1); } @Test public void reportsMismatchedFieldValues() throws JSONException { JSONCompareResult result = compareJSON("{\"id\": 3}", "{\"id\": 5}", LENIENT); assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n"))); - assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n"))); } @Test public void reportsMissingField() throws JSONException { JSONCompareResult result = compareJSON("{\"obj\": {\"id\": 3}}", "{\"obj\": {}}", LENIENT); assertThat(result, failsWithMessage(equalTo("obj\nExpected: id\n but none found\n"))); - assertEquals(result.getFieldMissing().size(), 1); } @Test @@ -79,7 +74,6 @@ public void reportsUnexpectedNonNull() throws JSONException { public void reportsUnexpectedFieldInNonExtensibleMode() throws JSONException { JSONCompareResult result = compareJSON("{\"obj\": {}}", "{\"obj\": {\"id\": 3}}", NON_EXTENSIBLE); assertThat(result, failsWithMessage(equalTo("obj\nUnexpected: id\n"))); - assertEquals(result.getFieldUnexpected().size(), 1); } @Test @@ -92,7 +86,6 @@ public void reportsMismatchedTypes() throws JSONException { public void reportsWrongSimpleValueCountInUnorderedArray() throws JSONException { JSONCompareResult result = compareJSON("[5, 5]", "[5, 7]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]: Expected 2 occurrence(s) of 5 but got 1 occurrence(s) ; []\nUnexpected: 7\n"))); - assertEquals(result.getFieldUnexpected().size(), 1); } @Test @@ -100,8 +93,6 @@ public void reportsMissingJSONObjectWithUniqueKeyInUnorderedArray() throws JSONE JSONCompareResult result = compareJSON("[{\"id\" : 3}]", "[{\"id\" : 5}]", LENIENT); assertThat(result, failsWithMessage(equalTo("[id=3]\nExpected: a JSON object\n but none found\n ; " + "[id=5]\nUnexpected: a JSON object\n"))); - assertEquals(result.getFieldMissing().size(), 1); - assertEquals(result.getFieldUnexpected().size(), 1); } @Test From 02ced087017c587e0ba7b157e42c640a0fcfa294 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Tue, 10 Nov 2015 14:57:00 -0800 Subject: [PATCH 08/84] Revert 252f48e78d7d91c6490e33052a2a3247806a3410 --- .../jsonassert/JSONCompareResult.java | 35 +++++++++++++++++++ .../jsonassert/JSONCompareTest.java | 9 +++++ 2 files changed, 44 insertions(+) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java index 2b772ac0..2cf7cad9 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java @@ -17,6 +17,8 @@ public class JSONCompareResult { private Object _expected; private Object _actual; private final List _fieldFailures = new ArrayList(); + private final List _fieldMissing = new ArrayList(); + private final List _fieldUnexpected = new ArrayList(); /** * Default constructor. @@ -60,6 +62,20 @@ public String getMessage() { public List getFieldFailures() { return Collections.unmodifiableList(_fieldFailures); } + + /** + * Get the list of missed on field comparisons + */ + public List getFieldMissing() { + return Collections.unmodifiableList(_fieldMissing); + } + + /** + * Get the list of failures on field comparisons + */ + public List getFieldUnexpected() { + return Collections.unmodifiableList(_fieldUnexpected); + } /** * Actual field value @@ -69,6 +85,7 @@ public List getFieldFailures() { * particular field * @deprecated Superseded by {@link #getFieldFailures()} */ + @Deprecated public Object getActual() { return _actual; } @@ -81,6 +98,7 @@ public Object getActual() { * particular field * @deprecated Superseded by {@link #getFieldFailures()} */ + @Deprecated public Object getExpected() { return _expected; } @@ -91,6 +109,20 @@ public Object getExpected() { public boolean isFailureOnField() { return !_fieldFailures.isEmpty(); } + + /** + * Check if comparison failed with missing on any particular fields + */ + public boolean isMissingOnField() { + return !_fieldMissing.isEmpty(); + } + + /** + * Check if comparison failed with unexpected on any particular fields + */ + public boolean isUnexpectedOnField() { + return !_fieldUnexpected.isEmpty(); + } /** * Dot-separated path the the field that failed comparison @@ -99,6 +131,7 @@ public boolean isFailureOnField() { * not fail on a particular field * @deprecated Superseded by {@link #getFieldFailures()} */ + @Deprecated public String getField() { return _field; } @@ -147,6 +180,7 @@ private String formatFailureMessage(String field, Object expected, Object actual } public JSONCompareResult missing(String field, Object expected) { + _fieldMissing.add(new FieldComparisonFailure(field, expected, null)); fail(formatMissing(field, expected)); return this; } @@ -159,6 +193,7 @@ private String formatMissing(String field, Object expected) { } public JSONCompareResult unexpected(String field, Object value) { + _fieldUnexpected.add(new FieldComparisonFailure(field, null, value)); fail(formatUnexpected(field, value)); return this; } diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java index c4727598..73531d79 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java @@ -1,6 +1,7 @@ package org.skyscreamer.jsonassert; import static org.hamcrest.core.IsEqual.equalTo; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.skyscreamer.jsonassert.JSONCompare.compareJSON; @@ -32,18 +33,22 @@ public void reportsArraysOfUnequalLength() throws JSONException { public void reportsArrayMissingExpectedElement() throws JSONException { JSONCompareResult result = compareJSON("[4]", "[7]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]\nExpected: 4\n but none found\n ; []\nUnexpected: 7\n"))); + assertEquals(result.getFieldMissing().size(), 1); + assertEquals(result.getFieldUnexpected().size(), 1); } @Test public void reportsMismatchedFieldValues() throws JSONException { JSONCompareResult result = compareJSON("{\"id\": 3}", "{\"id\": 5}", LENIENT); assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n"))); + assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n"))); } @Test public void reportsMissingField() throws JSONException { JSONCompareResult result = compareJSON("{\"obj\": {\"id\": 3}}", "{\"obj\": {}}", LENIENT); assertThat(result, failsWithMessage(equalTo("obj\nExpected: id\n but none found\n"))); + assertEquals(result.getFieldMissing().size(), 1); } @Test @@ -74,6 +79,7 @@ public void reportsUnexpectedNonNull() throws JSONException { public void reportsUnexpectedFieldInNonExtensibleMode() throws JSONException { JSONCompareResult result = compareJSON("{\"obj\": {}}", "{\"obj\": {\"id\": 3}}", NON_EXTENSIBLE); assertThat(result, failsWithMessage(equalTo("obj\nUnexpected: id\n"))); + assertEquals(result.getFieldUnexpected().size(), 1); } @Test @@ -86,6 +92,7 @@ public void reportsMismatchedTypes() throws JSONException { public void reportsWrongSimpleValueCountInUnorderedArray() throws JSONException { JSONCompareResult result = compareJSON("[5, 5]", "[5, 7]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]: Expected 2 occurrence(s) of 5 but got 1 occurrence(s) ; []\nUnexpected: 7\n"))); + assertEquals(result.getFieldUnexpected().size(), 1); } @Test @@ -93,6 +100,8 @@ public void reportsMissingJSONObjectWithUniqueKeyInUnorderedArray() throws JSONE JSONCompareResult result = compareJSON("[{\"id\" : 3}]", "[{\"id\" : 5}]", LENIENT); assertThat(result, failsWithMessage(equalTo("[id=3]\nExpected: a JSON object\n but none found\n ; " + "[id=5]\nUnexpected: a JSON object\n"))); + assertEquals(result.getFieldMissing().size(), 1); + assertEquals(result.getFieldUnexpected().size(), 1); } @Test From 679658a5a3b1b8fd0064309849ece7c553b876e5 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Tue, 10 Nov 2015 15:11:50 -0800 Subject: [PATCH 09/84] Fixed imports --- .../java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java index 8c7b97da..cc4a5bd2 100644 --- a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java @@ -6,7 +6,9 @@ import java.text.MessageFormat; +import org.json.JSONArray; import org.json.JSONException; +import org.json.JSONObject; import org.junit.Test; import org.skyscreamer.jsonassert.comparator.ArraySizeComparator; import org.skyscreamer.jsonassert.comparator.CustomComparator; @@ -221,6 +223,7 @@ public void verifyEveryArrayElementWithCustomComparator() throws JSONException { customizations[i] = new Customization(contextPath, regExValueMatcher); } CustomComparator regExComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, customizations); + ArrayValueMatcher regExArrayValueMatcher = new ArrayValueMatcher(regExComparator); Customization regExArrayValueCustomization = new Customization("a", regExArrayValueMatcher); CustomComparator regExCustomArrayValueComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, new Customization[] { regExArrayValueCustomization }); From 9fd51b65b2e41aa07beb9baa2b666c8131992586 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Wed, 16 Dec 2015 13:23:12 -0800 Subject: [PATCH 10/84] Prepare version and changelog for release --- CHANGELOG.md | 9 +++++++++ README.md | 2 +- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 880a8b30..4efce787 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ Changelog ========= +Version 1.3.0 - 12/16/2015 +-------------------------- + - Fix & improve ArrayValueMatcher JavaDoc (dmackinder) + Fix final JavaDoc example and add new example showing how to verify + every array element using a custom comparator + - Fix URL in pom.xml (aukevanleeuwen) + - Update JSONCompareResult.java adding 2 new lists for missing and unexpected fileds (riccorazza) + - Includes missing imports in test class (javierseixas) + Version 1.2.3 - 2/5/2014 ------------------------ - This edition brought to you by dmackinder (thanks!) diff --git a/README.md b/README.md index f2f58572..6e0dfda8 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert - 1.2.3 + 1.3.0 test diff --git a/src/site/resources/index.html b/src/site/resources/index.html index 2ceecb6c..0804b6f3 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

Introduction

  • JUnit
  • -


    The current version of JSONassert is 1.2.3

    +


    The current version of JSONassert is 1.3.0

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index 08342d85..01bddd20 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>1.2.3</version>
    +   <version>1.3.0</version>
    </dependency>
    From 2209d70729dd760e9cd89ec6ccce8edfa3649342 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Wed, 16 Dec 2015 13:24:31 -0800 Subject: [PATCH 11/84] [maven-release-plugin] prepare release jsonassert-1.3.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3c2e04b5..22e0c7b2 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.2.4-SNAPSHOT + 1.3.0 jar JSONassert From 8c9cf78250d6e28f39e90bc0288e94c02402decb Mon Sep 17 00:00:00 2001 From: Carter Page Date: Wed, 16 Dec 2015 13:24:34 -0800 Subject: [PATCH 12/84] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 22e0c7b2..efc547fa 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.3.0 + 1.3.1-SNAPSHOT jar JSONassert From 230ba924edd6f98452c8ec504e2ac1a7bbc8426b Mon Sep 17 00:00:00 2001 From: ctruchi Date: Thu, 31 Dec 2015 15:47:52 +0100 Subject: [PATCH 13/84] Support wildcards in Customization.path --- .../skyscreamer/jsonassert/Customization.java | 77 ++++++++++++++-- .../jsonassert/JSONCustomComparatorTest.java | 92 +++++++++++++++++++ 2 files changed, 163 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/Customization.java b/src/main/java/org/skyscreamer/jsonassert/Customization.java index 030f6e1e..d2e38d53 100644 --- a/src/main/java/org/skyscreamer/jsonassert/Customization.java +++ b/src/main/java/org/skyscreamer/jsonassert/Customization.java @@ -1,25 +1,90 @@ package org.skyscreamer.jsonassert; +import java.util.regex.Pattern; + /** * Associates a custom matcher to a specific jsonpath. */ public final class Customization { - private final String path; + private final Pattern path; private final ValueMatcher comparator; public Customization(String path, ValueMatcher comparator) { assert path != null; assert comparator != null; - this.path = path; + this.path = Pattern.compile(buildPattern(path)); this.comparator = comparator; } + private String buildPattern(String path) { + return buildPatternLevel1(path); + } + + private String buildPatternLevel1(String path) { + String regex = "\\*\\*\\."; + String replacement = "(?:.+\\.)?"; + + StringBuilder sb = new StringBuilder(); + String[] parts = path.split(regex); + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + + sb.append(buildPatternLevel2(part)); + if (i < parts.length - 1) { + sb.append(replacement); + } + } + + return sb.toString(); + } + + private String buildPatternLevel2(String s) { + if (s.isEmpty()) { + return ""; + } + String regex = "\\*\\*"; + String replacement = ".+"; + + StringBuilder sb = new StringBuilder(); + String[] parts = s.split(regex); + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + + sb.append(buildPatternLevel3(part)); + if (i < parts.length - 1) { + sb.append(replacement); + } + } + return sb.toString(); + } + + private String buildPatternLevel3(String s) { + if (s.isEmpty()) { + return ""; + } + + String regex = "\\*"; + String replacement = "[^\\.]+"; + + StringBuilder sb = new StringBuilder(); + String[] parts = s.split(regex); + for (int i = 0; i < parts.length; i++) { + String part = parts[i]; + + sb.append(Pattern.quote(part)); + if (i < parts.length - 1) { + sb.append(replacement); + } + } + return sb.toString(); + } + public static Customization customization(String path, ValueMatcher comparator) { return new Customization(path, comparator); } public boolean appliesToPath(String path) { - return this.path.equals(path); + return this.path.matcher(path).matches(); } /** @@ -27,7 +92,7 @@ public boolean appliesToPath(String path) { * Customization's comparator. Calls to this method should be replaced by * calls to matches(String prefix, Object actual, Object expected, * JSONCompareResult result). - * + * * @param actual * JSON value being tested * @param expected @@ -38,12 +103,12 @@ public boolean appliesToPath(String path) { public boolean matches(Object actual, Object expected) { return comparator.equal(actual, expected); } - + /** * Return true if actual value matches expected value using this * Customization's comparator. The equal method used for comparison depends * on type of comparator. - * + * * @param prefix * JSON path of the JSON item being tested (only used if * comparator is a LocationAwareValueMatcher) diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java index 897f1ad5..ac24f913 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java @@ -35,6 +35,75 @@ public class JSONCustomComparatorTest { " }\n" + "}"; + String simpleWildcardActual = "{\n" + + " \"foo\": {\n" + + " \"bar1\": {\n" + + " \"baz\": \"actual\"\n" + + " },\n" + + " \"bar2\": {\n" + + " \"baz\": \"actual\"\n" + + " }\n" + + " }\n" + + "}"; + String simpleWildcardExpected = "{\n" + + " \"foo\": {\n" + + " \"bar1\": {\n" + + " \"baz\": \"expected\"\n" + + " },\n" + + " \"bar2\": {\n" + + " \"baz\": \"expected\"\n" + + " }\n" + + " }\n" + + "}"; + + String deepWildcardActual = "{\n" + + " \"root\": {\n" + + " \"baz\": \"actual\",\n" + + " \"foo\": {\n" + + " \"baz\": \"actual\",\n" + + " \"bar\": {\n" + + " \"baz\": \"actual\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + String deepWildcardExpected = "{\n" + + " \"root\": {\n" + + " \"baz\": \"expected\",\n" + + " \"foo\": {\n" + + " \"baz\": \"expected\",\n" + + " \"bar\": {\n" + + " \"baz\": \"expected\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + + String rootDeepWildcardActual = "{\n" + + " \"baz\": \"actual\",\n" + + " \"root\": {\n" + + " \"baz\": \"actual\",\n" + + " \"foo\": {\n" + + " \"baz\": \"actual\",\n" + + " \"bar\": {\n" + + " \"baz\": \"actual\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + String rootDeepWildcardExpected = "{\n" + + " \"baz\": \"expected\",\n" + + " \"root\": {\n" + + " \"baz\": \"expected\",\n" + + " \"foo\": {\n" + + " \"baz\": \"expected\",\n" + + " \"bar\": {\n" + + " \"baz\": \"expected\"\n" + + " }\n" + + " }\n" + + " }\n" + + "}"; + int comparatorCallCount = 0; ValueMatcher comparator = new ValueMatcher() { @Override @@ -60,4 +129,27 @@ public void whenDeepPathMatchesCallCustomMatcher() throws JSONException { assertEquals(1, comparatorCallCount); } + @Test + public void whenSimpleWildcardPathMatchesCallCustomMatcher() throws JSONException { + JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new Customization("foo.*.baz", comparator)); + JSONCompareResult result = compareJSON(simpleWildcardExpected, simpleWildcardActual, jsonCmp); + assertTrue(result.getMessage(), result.passed()); + assertEquals(2, comparatorCallCount); + } + + @Test + public void whenDeepWildcardPathMatchesCallCustomMatcher() throws JSONException { + JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new Customization("root.**.baz", comparator)); + JSONCompareResult result = compareJSON(deepWildcardExpected, deepWildcardActual, jsonCmp); + assertTrue(result.getMessage(), result.passed()); + assertEquals(3, comparatorCallCount); + } + + @Test + public void whenRootDeepWildcardPathMatchesCallCustomMatcher() throws JSONException { + JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new Customization("**.baz", comparator)); + JSONCompareResult result = compareJSON(rootDeepWildcardExpected, rootDeepWildcardActual, jsonCmp); + assertTrue(result.getMessage(), result.passed()); + assertEquals(4, comparatorCallCount); + } } From ccc44f4e0476d15d346f486099d1d4e8aaa8f134 Mon Sep 17 00:00:00 2001 From: Adrian-Ryan Acala Date: Wed, 24 Feb 2016 20:21:01 -0800 Subject: [PATCH 14/84] Checking for null JSON strings prior to the JSONCompare so that it doesn't throw a NullPointerException. --- src/main/java/org/skyscreamer/jsonassert/JSONAssert.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java index 10ce2c1b..342d5d30 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java @@ -217,6 +217,12 @@ public static void assertNotEquals(String expectedStr, String actualStr, boolean */ public static void assertEquals(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(result.getMessage()); From 2f3576c72a28db3292740e5c67ffbc856394af96 Mon Sep 17 00:00:00 2001 From: David Biesack Date: Wed, 13 Jul 2016 13:14:56 -0400 Subject: [PATCH 15/84] Change the implementation bundle for org.json to one with a more open license. Use com.vaadin.external.google : android-json : 0.0.20131108.vaadin1 which has the Apache License 2.0 license: http://www.apache.org/licenses/LICENSE-2.0 Add source for org.json.JSONString interface, which is missing from the above bundle. --- README.md | 8 ++++++++ pom.xml | 8 ++++---- src/main/java/org/json/JSONString.java | 20 ++++++++++++++++++++ 3 files changed, 32 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/json/JSONString.java diff --git a/README.md b/README.md index 6e0dfda8..e8988717 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,14 @@ Who uses JSONassert? * * * +org.json +-------- + +This implementation uses a clean-room implementation of the org.json +library implemented for the Android system, released under the Apache 2.0 license. See +[com.vaadin.external.google:android-json](http://search.maven.org/#artifactdetails%7Ccom.vaadin.external.google%7Candroid-json%7C0.0.20131108.vaadin1%7Cjar) +That jar does **not** include the org.json.JSONString interface, so a new implementation of that interface is added to this source. + Resources --------- diff --git a/pom.xml b/pom.xml index efc547fa..c42703a4 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.3.1-SNAPSHOT + 1.4.0-SNAPSHOT jar JSONassert @@ -50,9 +50,9 @@ - org.json - json - 20090211 + com.vaadin.external.google + android-json + 0.0.20131108.vaadin1 junit diff --git a/src/main/java/org/json/JSONString.java b/src/main/java/org/json/JSONString.java new file mode 100644 index 00000000..e82cc246 --- /dev/null +++ b/src/main/java/org/json/JSONString.java @@ -0,0 +1,20 @@ +package org.json; + +/** + * The JSONString interface allows a toJSONString() method so that a class can change + * the behavior of JSONObject.toString(), JSONArray.toString(), and JSONWriter.value(Object). + * The toJSONString method will be used instead of the default behavior of using the + * Object's toString() method and quoting the result. + * + * @author sasdjb + * + */ +public interface JSONString { + + /** + * The toJSONString method allows a class to produce its own JSON + * serialization. + * */ + public String toJSONString(); + +} From dcab79c03ee56a91590583e399b364d6328be9b9 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 30 Oct 2016 17:09:28 -0400 Subject: [PATCH 16/84] Updated to new version and added CHANGELOG entry. --- CHANGELOG.md | 6 ++++++ README.md | 2 +- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4efce787..a277cef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Changelog ========= +Version 1.4.0 - 10/30/2016 +-------------------------- + - Change the implementation for org.json to one with a more open license + - Fix null pointer exception (issue #48) + - Support wildcards in Customization.path + Version 1.3.0 - 12/16/2015 -------------------------- - Fix & improve ArrayValueMatcher JavaDoc (dmackinder) diff --git a/README.md b/README.md index e8988717..77a83ce6 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert - 1.3.0 + 1.4.0 test diff --git a/src/site/resources/index.html b/src/site/resources/index.html index 0804b6f3..89c584e0 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

    Introduction

  • JUnit
  • -


    The current version of JSONassert is 1.3.0

    +


    The current version of JSONassert is 1.4.0

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index 01bddd20..79bc1205 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>1.3.0</version>
    +   <version>1.4.0</version>
    </dependency>
    From 3c97cf1db147c8440386bea575308d31f1306a94 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 30 Oct 2016 17:11:43 -0400 Subject: [PATCH 17/84] [maven-release-plugin] prepare release jsonassert-1.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c42703a4..3639d0cc 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.4.0-SNAPSHOT + 1.4.0 jar JSONassert From 3c2da7ae14ba0987ef021139bb8f0e9ff08ce9d2 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 30 Oct 2016 17:11:49 -0400 Subject: [PATCH 18/84] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3639d0cc..eb99a8df 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.4.0 + 1.4.1-SNAPSHOT jar JSONassert From 472f6cccb3ab00e949895733dd2b956ff9d02912 Mon Sep 17 00:00:00 2001 From: gil Date: Mon, 31 Oct 2016 11:15:56 +0100 Subject: [PATCH 19/84] add license headers --- src/main/java/org/json/JSONString.java | 16 ++++++++++++++++ .../jsonassert/ArrayValueMatcher.java | 16 ++++++++++++++++ .../skyscreamer/jsonassert/Customization.java | 14 ++++++++++++++ .../jsonassert/FieldComparisonFailure.java | 14 ++++++++++++++ .../org/skyscreamer/jsonassert/JSONAssert.java | 14 ++++++++++++++ .../org/skyscreamer/jsonassert/JSONCompare.java | 14 ++++++++++++++ .../skyscreamer/jsonassert/JSONCompareMode.java | 14 ++++++++++++++ .../jsonassert/JSONCompareResult.java | 14 ++++++++++++++ .../org/skyscreamer/jsonassert/JSONParser.java | 14 ++++++++++++++ .../jsonassert/LocationAwareValueMatcher.java | 16 ++++++++++++++++ .../RegularExpressionValueMatcher.java | 16 ++++++++++++++++ .../org/skyscreamer/jsonassert/ValueMatcher.java | 14 ++++++++++++++ .../jsonassert/ValueMatcherException.java | 16 ++++++++++++++++ .../comparator/AbstractComparator.java | 14 ++++++++++++++ .../comparator/ArraySizeComparator.java | 16 ++++++++++++++++ .../jsonassert/comparator/CustomComparator.java | 14 ++++++++++++++ .../jsonassert/comparator/DefaultComparator.java | 14 ++++++++++++++ .../jsonassert/comparator/JSONComparator.java | 16 ++++++++++++++++ .../jsonassert/comparator/JSONCompareUtil.java | 14 ++++++++++++++ .../jsonassert/ArrayValueMatcherTest.java | 16 ++++++++++++++++ .../skyscreamer/jsonassert/DependencyTest.java | 16 ++++++++++++++++ .../skyscreamer/jsonassert/JSONAssertTest.java | 14 ++++++++++++++ .../jsonassert/JSONCompareModeTest.java | 14 ++++++++++++++ .../skyscreamer/jsonassert/JSONCompareTest.java | 14 ++++++++++++++ .../jsonassert/JSONCustomComparatorTest.java | 14 ++++++++++++++ .../RegularExpressionValueMatcherTest.java | 16 ++++++++++++++++ .../comparator/ArraySizeComparatorTest.java | 16 ++++++++++++++++ .../comparator/CustomComparatorTest.java | 16 ++++++++++++++++ .../comparator/JSONCompareUtilTest.java | 16 ++++++++++++++++ 29 files changed, 432 insertions(+) diff --git a/src/main/java/org/json/JSONString.java b/src/main/java/org/json/JSONString.java index e82cc246..ee34e818 100644 --- a/src/main/java/org/json/JSONString.java +++ b/src/main/java/org/json/JSONString.java @@ -1,3 +1,19 @@ +/* + * Copyright 2016 sasdjb. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.json; /** diff --git a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java index 1ffd7a5a..5dd378ff 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Duncan Mackinder. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import java.text.MessageFormat; diff --git a/src/main/java/org/skyscreamer/jsonassert/Customization.java b/src/main/java/org/skyscreamer/jsonassert/Customization.java index d2e38d53..7efdff49 100644 --- a/src/main/java/org/skyscreamer/jsonassert/Customization.java +++ b/src/main/java/org/skyscreamer/jsonassert/Customization.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import java.util.regex.Pattern; diff --git a/src/main/java/org/skyscreamer/jsonassert/FieldComparisonFailure.java b/src/main/java/org/skyscreamer/jsonassert/FieldComparisonFailure.java index 73d5b4d9..a4746f24 100644 --- a/src/main/java/org/skyscreamer/jsonassert/FieldComparisonFailure.java +++ b/src/main/java/org/skyscreamer/jsonassert/FieldComparisonFailure.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; /** diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java index 342d5d30..0fd2474a 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import org.json.JSONArray; diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java index fc41bf4f..00fa99d5 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import org.json.JSONArray; diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java index a4df7e07..7548e0a7 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; /** diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java index 2cf7cad9..be181ad8 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import java.util.ArrayList; diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONParser.java b/src/main/java/org/skyscreamer/jsonassert/JSONParser.java index 45df77c1..ab5c329f 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONParser.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONParser.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import org.json.JSONArray; diff --git a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java index 56653cfa..df492744 100644 --- a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Duncan Mackinder. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + /** * */ diff --git a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java index 7efb64eb..9f1a1baf 100644 --- a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Duncan Mackinder. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import java.util.regex.Pattern; diff --git a/src/main/java/org/skyscreamer/jsonassert/ValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ValueMatcher.java index 58a86cf9..ffd20f4c 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/ValueMatcher.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; public interface ValueMatcher { diff --git a/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java b/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java index 3639afce..abd44e3c 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java +++ b/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Duncan Mackinder. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; /** diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java index 037bb6af..1743ce14 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import org.json.JSONArray; diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java index e426cb8e..059325b5 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Duncan Mackinder. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import java.text.MessageFormat; diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java index 4adb2b69..ca326844 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import org.json.JSONException; diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java index e2f6b57a..52052f0f 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import org.json.JSONArray; diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java index b5b950fb..4e4678d6 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013 Ivan Zaytsev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import org.json.JSONArray; diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java index 6d28dd97..965db67b 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import org.json.JSONArray; diff --git a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java index cc4a5bd2..cb0c0712 100644 --- a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Duncan Mackinder. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import static org.junit.Assert.assertEquals; diff --git a/src/test/java/org/skyscreamer/jsonassert/DependencyTest.java b/src/test/java/org/skyscreamer/jsonassert/DependencyTest.java index fe449060..37b6d44d 100644 --- a/src/test/java/org/skyscreamer/jsonassert/DependencyTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/DependencyTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Carter Page. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import org.json.JSONObject; diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java index 65014b68..2d59f74f 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import java.util.Arrays; diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCompareModeTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCompareModeTest.java index bf032293..df808855 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCompareModeTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCompareModeTest.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import static junit.framework.Assert.assertEquals; diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java index 73531d79..450adfde 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import static org.hamcrest.core.IsEqual.equalTo; diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java index ac24f913..5f4c36ca 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java @@ -1,3 +1,17 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import org.json.JSONException; diff --git a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java index 41381309..9e644596 100644 --- a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Duncan Mackinder. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert; import org.junit.Assert; diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java index e554b92b..4449ff43 100644 --- a/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 Duncan Mackinder. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import static org.junit.Assert.assertTrue; diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java index 4f5ff05c..5c304c99 100644 --- a/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013 Ivan Zaytsev. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import junit.framework.Assert; diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java index e07a8838..d7691732 100644 --- a/src/test/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2013 Carter Page. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. +*/ + package org.skyscreamer.jsonassert.comparator; import junit.framework.Assert; From 5336b3d12e35ca714f81dca0a9f30876662873ac Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Thu, 16 Feb 2017 18:24:54 +0100 Subject: [PATCH 20/84] Fix method reference in javadoc --- src/main/java/org/skyscreamer/jsonassert/JSONAssert.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java index 342d5d30..937c1b4c 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java @@ -56,7 +56,7 @@ public static void assertEquals(String expectedStr, JSONObject actual, boolean s * Asserts that the JSONObject provided does not match the expected string. If it is it throws an * {@link AssertionError}. * - * @see #assertEquals(String JSONObject, boolean) + * @see #assertEquals(String, JSONObject, boolean) * * @param expectedStr Expected JSON string * @param actual JSONObject to compare From b373db0103130c5dd1a3da0324d89260efde0241 Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Thu, 16 Feb 2017 18:26:57 +0100 Subject: [PATCH 21/84] Fix typo in quickstart.html reported in issue 74 --- src/site/resources/quickstart.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index 79bc1205..bf82a545 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -75,7 +75,7 @@

    Quick Start

    It is recommended that you leave strictMode - off, so your will be tests less brittle. + off, so your tests will be less brittle. Turn it on if you need to enforce a particular order for arrays, or if you want to ensure that the actual JSON does not have any fields beyond what's expected.

    From bdcc9fd3c363700abd7bcbb024961d3f0b72745d Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Thu, 16 Feb 2017 21:47:43 +0100 Subject: [PATCH 22/84] Add missing section closing tags in cookbook and quickstart --- src/site/resources/cookbook.html | 2 +- src/site/resources/quickstart.html | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/site/resources/cookbook.html b/src/site/resources/cookbook.html index 0ca0eb7a..2e271348 100644 --- a/src/site/resources/cookbook.html +++ b/src/site/resources/cookbook.html @@ -132,6 +132,6 @@

    Cookbook

    result, true); // Pass
    - + diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index bf82a545..ddcb7f91 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -78,5 +78,6 @@

    Quick Start

    off, so your tests will be less brittle. Turn it on if you need to enforce a particular order for arrays, or if you want to ensure that the actual JSON does not have any fields beyond what's expected.

    + From 6cb2c48fadf0b9599545d8ec997c903d76d16447 Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Thu, 16 Feb 2017 21:49:07 +0100 Subject: [PATCH 23/84] Fix javadoc params in ArrayValueMatcher --- .../java/org/skyscreamer/jsonassert/ArrayValueMatcher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java index 1ffd7a5a..ddc849de 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java @@ -147,8 +147,8 @@ public ArrayValueMatcher(JSONComparator comparator, int index) { * * @param comparator * comparator to use to compare elements - * @from first element in actual array to compared - * @to last element in actual array to compared + * @param from first element in actual array to compared + * @param to last element in actual array to compared */ public ArrayValueMatcher(JSONComparator comparator, int from, int to) { assert comparator != null : "comparator null"; From 1a6b90f9a32818140a130626818e4572a8950caa Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Fri, 17 Feb 2017 19:59:05 +0100 Subject: [PATCH 24/84] Add javadoc to a couple of methods --- .../skyscreamer/jsonassert/ValueMatcher.java | 12 ++ .../jsonassert/comparator/JSONComparator.java | 46 ++++++++ .../comparator/JSONCompareUtil.java | 106 +++++++++++++++--- 3 files changed, 147 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/ValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ValueMatcher.java index 58a86cf9..e52d893f 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/ValueMatcher.java @@ -1,7 +1,19 @@ package org.skyscreamer.jsonassert; +/** + * Represents a value matcher that can compare two objects for equality. + * + * @param the object type to compare + */ public interface ValueMatcher { + /** + * Compares the two provided objects whether they are equal. + * + * @param o1 the first object to check + * @param o2 the object to check the first against + * @return true if the objects are equal, false otherwise + */ boolean equal(T o1, T o2); } diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java index b5b950fb..0574e0fe 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java @@ -13,13 +13,59 @@ */ public interface JSONComparator { + /** + * Compares two {@link JSONObject}s and returns the result of the comparison in a {@link JSONCompareResult} object. + * + * @param expected the expected JSON object + * @param actual the actual JSON object + * @return the result of the comparison + * @throws JSONException + */ JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) throws JSONException; + /** + * Compares two {@link JSONArray}s and returns the result of the comparison in a {@link JSONCompareResult} object. + * + * @param expected the expected JSON array + * @param actual the actual JSON array + * @return the result of the comparison + * @throws JSONException + */ JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) throws JSONException; + /** + * Compares two {@link JSONObject}s on the provided path represented by {@code prefix} and + * updates the result of the comparison in the {@code result} {@link JSONCompareResult} object. + * + * @param prefix the path in the json where the comparison happens + * @param expected the expected JSON object + * @param actual the actual JSON object + * @param result stores the actual state of the comparison result + * @throws JSONException + */ void compareJSON(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) throws JSONException; + /** + * Compares two {@link Object}s on the provided path represented by {@code prefix} and + * updates the result of the comparison in the {@code result} {@link JSONCompareResult} object. + * + * @param prefix the path in the json where the comparison happens + * @param expectedValue the expected value + * @param actualValue the actual value + * @param result stores the actual state of the comparison result + * @throws JSONException + */ void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException; + /** + * Compares two {@link JSONArray}s on the provided path represented by {@code prefix} and + * updates the result of the comparison in the {@code result} {@link JSONCompareResult} object. + * + * @param prefix the path in the json where the comparison happens + * @param expected the expected JSON array + * @param actual the actual JSON array + * @param result stores the actual state of the comparison result + * @throws JSONException + */ void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException; } diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java index 6d28dd97..273c8161 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java @@ -1,34 +1,58 @@ package org.skyscreamer.jsonassert.comparator; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import java.util.*; - /** - * Utility class that contains Json manipulation methods + * Utility class that contains Json manipulation methods. */ public final class JSONCompareUtil { private static Integer INTEGER_ONE = new Integer(1); - private JSONCompareUtil() {} + private JSONCompareUtil() { + } - public static Map arrayOfJsonObjectToMap(JSONArray array, String uniqueKey) throws JSONException { + /** + * Converts the provided {@link JSONArray} to a Map of {@link JSONObject}s where the key of each object + * is the value at {@code uniqueKey} in each object. + * + * @param array the JSON array to convert + * @param uniqueKey the key to map the JSON objects to + * @return the map of {@link JSONObject}s from {@code array} + * @throws JSONException + */ + public static Map arrayOfJsonObjectToMap(JSONArray array, String uniqueKey) throws JSONException { Map valueMap = new HashMap(); - for(int i = 0 ; i < array.length() ; ++i) { - JSONObject jsonObject = (JSONObject)array.get(i); + for (int i = 0; i < array.length(); ++i) { + JSONObject jsonObject = (JSONObject) array.get(i); Object id = jsonObject.get(uniqueKey); valueMap.put(id, jsonObject); } return valueMap; } - + /** + * Searches for the unique key of the {@code expected} JSON array. + * + * @param expected the array to find the unique key of + * @return the unique key if there's any, otherwise null + * @throws JSONException + */ public static String findUniqueKey(JSONArray expected) throws JSONException { // Find a unique key for the object (id, name, whatever) - JSONObject o = (JSONObject)expected.get(0); // There's at least one at this point - for(String candidate : getKeys(o)) { + JSONObject o = (JSONObject) expected.get(0); // There's at least one at this point + for (String candidate : getKeys(o)) { if (isUsableAsUniqueKey(candidate, expected)) return candidate; } // No usable unique key :-( @@ -41,7 +65,7 @@ public static String findUniqueKey(JSONArray expected) throws JSONException { */ public static boolean isUsableAsUniqueKey(String candidate, JSONArray array) throws JSONException { Set seenValues = new HashSet(); - for (int i = 0 ; i < array.length() ; i++) { + for (int i = 0; i < array.length(); i++) { Object item = array.get(i); if (item instanceof JSONObject) { JSONObject o = (JSONObject) item; @@ -62,16 +86,31 @@ public static boolean isUsableAsUniqueKey(String candidate, JSONArray array) thr return true; } + /** + * Converts the given {@link JSONArray} to a list of {@link Object}s. + * + * @param expected the JSON array to convert + * @return the list of objects from the {@code expected} array + * @throws JSONException + */ public static List jsonArrayToList(JSONArray expected) throws JSONException { List jsonObjects = new ArrayList(expected.length()); - for(int i = 0 ; i < expected.length() ; ++i) { + for (int i = 0; i < expected.length(); ++i) { jsonObjects.add(expected.get(i)); } return jsonObjects; } + /** + * Returns whether all of the elements in the given array are simple values. + * + * @param array the JSON array to iterate through on + * @return true if all the elements in {@code array} are simple values + * @throws JSONException + * @see #isSimpleValue(Object) + */ public static boolean allSimpleValues(JSONArray array) throws JSONException { - for(int i = 0 ; i < array.length() ; ++i) { + for (int i = 0; i < array.length(); ++i) { if (!isSimpleValue(array.get(i))) { return false; } @@ -79,12 +118,25 @@ public static boolean allSimpleValues(JSONArray array) throws JSONException { return true; } + /** + * Returns whether the given object is a simple value: not {@link JSONObject} and not {@link JSONArray}. + * + * @param o the object to inspect + * @return true if {@code o} is a simple value + */ public static boolean isSimpleValue(Object o) { return !(o instanceof JSONObject) && !(o instanceof JSONArray); } + /** + * Returns whether all elements in {@code array} are {@link JSONObject} instances. + * + * @param array the array to inspect + * @return true if all the elements in the given array are JSONObjects + * @throws JSONException + */ public static boolean allJSONObjects(JSONArray array) throws JSONException { - for(int i = 0 ; i < array.length() ; ++i) { + for (int i = 0; i < array.length(); ++i) { if (!(array.get(i) instanceof JSONObject)) { return false; } @@ -92,8 +144,15 @@ public static boolean allJSONObjects(JSONArray array) throws JSONException { return true; } + /** + * Returns whether all elements in {@code array} are {@link JSONArray} instances. + * + * @param array the array to inspect + * @return true if all the elements in the given array are JSONArrays + * @throws JSONException + */ public static boolean allJSONArrays(JSONArray array) throws JSONException { - for(int i = 0 ; i < array.length() ; ++i) { + for (int i = 0; i < array.length(); ++i) { if (!(array.get(i) instanceof JSONArray)) { return false; } @@ -101,11 +160,17 @@ public static boolean allJSONArrays(JSONArray array) throws JSONException { return true; } + /** + * Collects all keys in {@code jsonObject}. + * + * @param jsonObject the {@link JSONObject} to get the keys of + * @return the set of keys + */ public static Set getKeys(JSONObject jsonObject) { Set keys = new TreeSet(); Iterator iter = jsonObject.keys(); - while(iter.hasNext()) { - keys.add((String)iter.next()); + while (iter.hasNext()) { + keys.add((String) iter.next()); } return keys; } @@ -118,6 +183,13 @@ public static String formatUniqueKey(String key, String uniqueKey, Object value) return key + "[" + uniqueKey + "=" + value + "]"; } + /** + * Creates a cardinality map from {@code coll}. + * + * @param coll the collection of items to convert + * @param the type of elements in the input collection + * @return the cardinality map + */ public static Map getCardinalityMap(final Collection coll) { Map count = new HashMap(); for (T item : coll) { From c324cffb67a44bfc1f6ec149ba5d9396ca3c4c7f Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Fri, 17 Feb 2017 20:09:52 +0100 Subject: [PATCH 25/84] Remove unnecessary access modifiers --- src/main/java/org/json/JSONString.java | 4 ++-- src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/json/JSONString.java b/src/main/java/org/json/JSONString.java index e82cc246..6ba68fa7 100644 --- a/src/main/java/org/json/JSONString.java +++ b/src/main/java/org/json/JSONString.java @@ -5,7 +5,7 @@ * the behavior of JSONObject.toString(), JSONArray.toString(), and JSONWriter.value(Object). * The toJSONString method will be used instead of the default behavior of using the * Object's toString() method and quoting the result. - * + * * @author sasdjb * */ @@ -15,6 +15,6 @@ public interface JSONString { * The toJSONString method allows a class to produce its own JSON * serialization. * */ - public String toJSONString(); + String toJSONString(); } diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java index a4df7e07..849e1cab 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java @@ -52,7 +52,7 @@ public enum JSONCompareMode { private final boolean _extensible; private final boolean _strictOrder; - private JSONCompareMode(boolean extensible, boolean strictOrder) { + JSONCompareMode(boolean extensible, boolean strictOrder) { _extensible = extensible; _strictOrder = strictOrder; } From 9a62815cc6434660d50e79e6b73c8bdb2d56ceb0 Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Fri, 17 Feb 2017 20:16:09 +0100 Subject: [PATCH 26/84] Extract some logic to methods in DefaultComparator to improve readability --- .../comparator/DefaultComparator.java | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java index e2f6b57a..7df04b44 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java @@ -1,17 +1,17 @@ package org.skyscreamer.jsonassert.comparator; +import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allJSONObjects; +import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allSimpleValues; + import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.JSONCompareResult; -import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allJSONObjects; -import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allSimpleValues; - /** * This class is the default json comparator implementation.

    - * Comparison is performed according to {@link JSONCompareMode} that is passed as constructor's argument. + * Comparison is performed according to {@link JSONCompareMode} that is passed as constructor's argument. */ public class DefaultComparator extends AbstractComparator { @@ -36,8 +36,8 @@ public void compareJSON(String prefix, JSONObject expected, JSONObject actual, J @Override public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException { - if (expectedValue instanceof Number && actualValue instanceof Number) { - if (((Number)expectedValue).doubleValue() != ((Number)actualValue).doubleValue()) { + if (areNumbers(expectedValue, actualValue)) { + if (areSameDoubles(expectedValue, actualValue)) { result.fail(prefix, expectedValue, actualValue); } } else if (expectedValue.getClass().isAssignableFrom(actualValue.getClass())) { @@ -74,4 +74,12 @@ public void compareJSONArray(String prefix, JSONArray expected, JSONArray actual recursivelyCompareJSONArray(prefix, expected, actual, result); } } + + private boolean areNumbers(Object expectedValue, Object actualValue) { + return expectedValue instanceof Number && actualValue instanceof Number; + } + + private boolean areSameDoubles(Object expectedValue, Object actualValue) { + return ((Number) expectedValue).doubleValue() != ((Number) actualValue).doubleValue(); + } } From 7a4b0821039d9802cbcebbf1292601025823007d Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Fri, 17 Feb 2017 20:22:54 +0100 Subject: [PATCH 27/84] Deduplicate string building logic in Customization --- .../skyscreamer/jsonassert/Customization.java | 59 ++++++++++--------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/Customization.java b/src/main/java/org/skyscreamer/jsonassert/Customization.java index d2e38d53..b030f158 100644 --- a/src/main/java/org/skyscreamer/jsonassert/Customization.java +++ b/src/main/java/org/skyscreamer/jsonassert/Customization.java @@ -24,18 +24,7 @@ private String buildPatternLevel1(String path) { String regex = "\\*\\*\\."; String replacement = "(?:.+\\.)?"; - StringBuilder sb = new StringBuilder(); - String[] parts = path.split(regex); - for (int i = 0; i < parts.length; i++) { - String part = parts[i]; - - sb.append(buildPatternLevel2(part)); - if (i < parts.length - 1) { - sb.append(replacement); - } - } - - return sb.toString(); + return buildPattern(path, regex, replacement, 1); } private String buildPatternLevel2(String s) { @@ -45,17 +34,7 @@ private String buildPatternLevel2(String s) { String regex = "\\*\\*"; String replacement = ".+"; - StringBuilder sb = new StringBuilder(); - String[] parts = s.split(regex); - for (int i = 0; i < parts.length; i++) { - String part = parts[i]; - - sb.append(buildPatternLevel3(part)); - if (i < parts.length - 1) { - sb.append(replacement); - } - } - return sb.toString(); + return buildPattern(s, regex, replacement, 2); } private String buildPatternLevel3(String s) { @@ -66,19 +45,41 @@ private String buildPatternLevel3(String s) { String regex = "\\*"; String replacement = "[^\\.]+"; + return buildPattern(s, regex, replacement, 3); + } + + private String buildPattern(String path, String regex, String replacement, int level) { StringBuilder sb = new StringBuilder(); - String[] parts = s.split(regex); + String[] parts = path.split(regex); for (int i = 0; i < parts.length; i++) { - String part = parts[i]; - - sb.append(Pattern.quote(part)); + sb.append(buildPatternForLevel(level, parts[i])); if (i < parts.length - 1) { sb.append(replacement); - } - } + } + } return sb.toString(); } + private String buildPatternForLevel(int level, String part) { + switch (level) { + case 1: + return buildPatternLevel2(part); + case 2: + return buildPatternLevel3(part); + case 3: + return Pattern.quote(part); + default: + return "Incorrect level."; + } + } + + /** + * Creates a new {@link Customization} instance for {@code path} and {@code comparator}. + * + * @param path the json path + * @param comparator the comparator + * @return a new Customization + */ public static Customization customization(String path, ValueMatcher comparator) { return new Customization(path, comparator); } From ecd41b9c31b1caaa134f46d61dfef924c304f6f3 Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Mon, 20 Feb 2017 07:01:52 +0100 Subject: [PATCH 28/84] Change access modifier to protected in case DefaultComparator gets inherited --- .../jsonassert/comparator/DefaultComparator.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java index 7df04b44..5ef62c63 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java @@ -1,14 +1,14 @@ package org.skyscreamer.jsonassert.comparator; -import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allJSONObjects; -import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allSimpleValues; - import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.JSONCompareResult; +import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allJSONObjects; +import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allSimpleValues; + /** * This class is the default json comparator implementation.

    * Comparison is performed according to {@link JSONCompareMode} that is passed as constructor's argument. @@ -75,11 +75,11 @@ public void compareJSONArray(String prefix, JSONArray expected, JSONArray actual } } - private boolean areNumbers(Object expectedValue, Object actualValue) { + protected boolean areNumbers(Object expectedValue, Object actualValue) { return expectedValue instanceof Number && actualValue instanceof Number; } - private boolean areSameDoubles(Object expectedValue, Object actualValue) { + protected boolean areSameDoubles(Object expectedValue, Object actualValue) { return ((Number) expectedValue).doubleValue() != ((Number) actualValue).doubleValue(); } } From b4307f967459ff5369f607c40960ca43ddeeded8 Mon Sep 17 00:00:00 2001 From: Tamas Balog Date: Fri, 24 Feb 2017 21:15:30 +0100 Subject: [PATCH 29/84] Fix method name --- .../skyscreamer/jsonassert/comparator/DefaultComparator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java index 5ef62c63..74ce8146 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java @@ -37,7 +37,7 @@ public void compareJSON(String prefix, JSONObject expected, JSONObject actual, J public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException { if (areNumbers(expectedValue, actualValue)) { - if (areSameDoubles(expectedValue, actualValue)) { + if (areNotSameDoubles(expectedValue, actualValue)) { result.fail(prefix, expectedValue, actualValue); } } else if (expectedValue.getClass().isAssignableFrom(actualValue.getClass())) { @@ -79,7 +79,7 @@ protected boolean areNumbers(Object expectedValue, Object actualValue) { return expectedValue instanceof Number && actualValue instanceof Number; } - protected boolean areSameDoubles(Object expectedValue, Object actualValue) { + protected boolean areNotSameDoubles(Object expectedValue, Object actualValue) { return ((Number) expectedValue).doubleValue() != ((Number) actualValue).doubleValue(); } } From 46980dc815c79caab618f7602e3ab86fec86d319 Mon Sep 17 00:00:00 2001 From: yasinb Date: Sat, 18 Mar 2017 09:00:16 +0530 Subject: [PATCH 30/84] Overloaded methods to add methods - fixes #42 - assertEquals accepts message - junits for assertEquals - minor improvements in existing junits --- .../skyscreamer/jsonassert/JSONAssert.java | 382 +++++++++++++++++- .../jsonassert/JSONAssertTest.java | 281 ++++++++++++- 2 files changed, 628 insertions(+), 35 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java index 342d5d30..a243a3c3 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java @@ -51,6 +51,21 @@ public static void assertEquals(String expectedStr, JSONObject actual, boolean s throws JSONException { assertEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } + + /** + * Asserts that the JSONObject 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 actual JSONObject to compare + * @param strict Enables strict checking + * @throws JSONException + */ + public static void assertEquals(String message, String expectedStr, JSONObject actual, boolean strict) + throws JSONException { + assertEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + } /** * Asserts that the JSONObject provided does not match the expected string. If it is it throws an @@ -67,6 +82,23 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, boolea throws JSONException { assertNotEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } + + /** + * Asserts that the JSONObject provided does not match the expected string. If it is it throws an + * {@link AssertionError}. + * + * @see #assertEquals(String JSONObject, boolean) + * + * @param message Error message to be displayed in case of assertion failure + * @param expectedStr Expected JSON string + * @param actual JSONObject to compare + * @param strict Enables strict checking + * @throws JSONException + */ + public static void assertNotEquals(String message, String expectedStr, JSONObject actual, boolean strict) + throws JSONException { + assertNotEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + } /** * Asserts that the JSONObject provided matches the expected string. If it isn't it throws an @@ -79,9 +111,24 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, boolea */ public static void assertEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) throws JSONException { + assertEquals("", expectedStr, actual, compareMode); + } + + /** + * Asserts that the JSONObject 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 actual JSONObject to compare + * @param compareMode Specifies which comparison mode to use + * @throws JSONException + */ + public static void assertEquals(String message, String expectedStr, JSONObject actual, JSONCompareMode compareMode) + throws JSONException { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONObject) { - assertEquals((JSONObject)expected, actual, compareMode); + assertEquals(message, (JSONObject)expected, actual, compareMode); } else { throw new AssertionError("Expecting a JSON array, but passing in a JSON object"); @@ -101,9 +148,26 @@ public static void assertEquals(String expectedStr, JSONObject actual, JSONCompa */ public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) throws JSONException { + assertNotEquals("", expectedStr, actual, compareMode); + } + + /** + * Asserts that the JSONObject provided does not match the expected string. If it is it throws an + * {@link AssertionError}. + * + * @see #assertEquals(String, JSONObject, JSONCompareMode) + * + * @param message Error message to be displayed in case of assertion failure + * @param expectedStr Expected JSON string + * @param actual JSONObject to compare + * @param compareMode Specifies which comparison mode to use + * @throws JSONException + */ + public static void assertNotEquals(String message, String expectedStr, JSONObject actual, JSONCompareMode compareMode) + throws JSONException { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONObject) { - assertNotEquals((JSONObject) expected, actual, compareMode); + assertNotEquals(message, (JSONObject) expected, actual, compareMode); } else { throw new AssertionError("Expecting a JSON array, but passing in a JSON object"); @@ -123,6 +187,21 @@ public static void assertEquals(String expectedStr, JSONArray actual, boolean st throws JSONException { assertEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } + + /** + * 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 actual JSONArray to compare + * @param strict Enables strict checking + * @throws JSONException + */ + public static void assertEquals(String message, String expectedStr, JSONArray actual, boolean strict) + throws JSONException { + assertEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + } /** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an @@ -137,6 +216,21 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, boolean throws JSONException { assertNotEquals(expectedStr, actual, 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 message Error message to be displayed in case of assertion failure + * @param expectedStr Expected JSON string + * @param actual JSONArray to compare + * @param strict Enables strict checking + * @throws JSONException + */ + public static void assertNotEquals(String message, String expectedStr, JSONArray actual, boolean strict) + throws JSONException { + assertNotEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + } /** * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an @@ -149,9 +243,24 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, boolean */ public static void assertEquals(String expectedStr, JSONArray actual, JSONCompareMode compareMode) throws JSONException { + assertEquals("", expectedStr, actual, compareMode); + } + + /** + * 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 actual JSONArray to compare + * @param compareMode Specifies which comparison mode to use + * @throws JSONException + */ + public static void assertEquals(String message, String expectedStr, JSONArray actual, JSONCompareMode compareMode) + throws JSONException { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONArray) { - assertEquals((JSONArray) expected, actual, compareMode); + assertEquals(message, (JSONArray) expected, actual, compareMode); } else { throw new AssertionError("Expecting a JSON object, but passing in a JSON array"); @@ -177,6 +286,27 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCom throw new AssertionError("Expecting a JSON object, but passing in a JSON array"); } } + + /** + * Asserts that the JSONArray 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 actual JSONArray to compare + * @param compareMode Specifies which comparison mode to use + * @throws JSONException + */ + public static void assertNotEquals(String message, String expectedStr, JSONArray actual, JSONCompareMode compareMode) + throws JSONException { + Object expected = JSONParser.parseJSON(expectedStr); + if (expected instanceof JSONArray) { + assertNotEquals(message, (JSONArray) expected, actual, compareMode); + } + else { + throw new AssertionError("Expecting a JSON object, but passing in a JSON array"); + } + } /** * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an @@ -191,6 +321,21 @@ public static void assertEquals(String expectedStr, String actualStr, boolean st throws JSONException { assertEquals(expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } + + /** + * 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 strict Enables strict checking + * @throws JSONException + */ + public static void assertEquals(String message, String expectedStr, String actualStr, boolean strict) + throws JSONException { + assertEquals(message, expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + } /** * Asserts that the JSONArray provided does not match the expected string. If it is it throws an @@ -205,6 +350,21 @@ public static void assertNotEquals(String expectedStr, String actualStr, boolean throws JSONException { assertNotEquals(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 message Error message to be displayed in case of assertion failure + * @param expectedStr Expected JSON string + * @param actualStr String to compare + * @param strict Enables strict checking + * @throws JSONException + */ + public static void assertNotEquals(String message, String expectedStr, String actualStr, boolean strict) + throws JSONException { + assertNotEquals(message, expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + } /** * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an @@ -217,6 +377,21 @@ public static void assertNotEquals(String expectedStr, String actualStr, boolean */ public static void assertEquals(String expectedStr, String actualStr, JSONCompareMode compareMode) throws JSONException { + assertEquals("", expectedStr, actualStr, compareMode); + } + + /** + * 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 + */ + 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."); @@ -225,7 +400,7 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar } JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, compareMode); if (result.failed()) { - throw new AssertionError(result.getMessage()); + throw new AssertionError(getCombinedMessage(message, result.getMessage())); } } @@ -240,9 +415,24 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar */ public static void assertNotEquals(String expectedStr, String actualStr, JSONCompareMode compareMode) throws JSONException { + assertNotEquals("", expectedStr, actualStr, compareMode); + } + + /** + * Asserts that the JSONArray 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 compareMode Specifies which comparison mode to use + * @throws JSONException + */ + public static void assertNotEquals(String message, String expectedStr, String actualStr, JSONCompareMode compareMode) + throws JSONException { JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, compareMode); if (result.passed()) { - throw new AssertionError(result.getMessage()); + throw new AssertionError(getCombinedMessage(message, result.getMessage())); } } @@ -257,9 +447,25 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom */ public static void assertEquals(String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { + assertEquals("", expectedStr, actualStr, comparator); + + } + + /** + * 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 + */ + 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(result.getMessage()); + throw new AssertionError(getCombinedMessage(message, result.getMessage())); } } @@ -274,9 +480,24 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar */ public static void assertNotEquals(String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { + assertNotEquals("", expectedStr, actualStr, comparator); + } + + /** + * 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 + */ + 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(result.getMessage()); + throw new AssertionError(getCombinedMessage(message, result.getMessage())); } } @@ -293,6 +514,21 @@ public static void assertEquals(JSONObject expected, JSONObject actual, boolean throws JSONException { assertEquals(expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } + + /** + * 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 strict Enables strict checking + * @throws JSONException + */ + public static void assertEquals(String message, JSONObject expected, JSONObject actual, boolean strict) + throws JSONException { + assertEquals(message, expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + } /** * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an @@ -307,6 +543,21 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, boole throws JSONException { assertNotEquals(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 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 + */ + 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 JSONObject provided matches the expected JSONObject. If it isn't it throws an @@ -318,11 +569,25 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, boole * @throws JSONException */ public static void assertEquals(JSONObject expected, JSONObject actual, JSONCompareMode compareMode) - throws JSONException - { + throws JSONException { + assertEquals("", expected, actual, 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 + */ + 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(result.getMessage()); + throw new AssertionError(getCombinedMessage(message, result.getMessage())); } } @@ -336,11 +601,25 @@ public static void assertEquals(JSONObject expected, JSONObject actual, JSONComp * @throws JSONException */ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONCompareMode compareMode) - throws JSONException - { + throws JSONException { + assertNotEquals("", expected, actual, compareMode); + } + + /** + * 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 + */ + 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(result.getMessage()); + throw new AssertionError(getCombinedMessage(message, result.getMessage())); } } @@ -355,7 +634,22 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONC */ public static void assertEquals(JSONArray expected, JSONArray actual, boolean strict) throws JSONException { - assertEquals(expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + assertEquals("", expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); + } + + /** + * 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 strict Enables strict checking + * @throws JSONException + */ + public static void assertEquals(String message, JSONArray expected, JSONArray actual, boolean strict) + throws JSONException { + assertEquals(message, expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } /** @@ -371,6 +665,21 @@ public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean throws JSONException { assertNotEquals(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 strict Enables strict checking + * @throws JSONException + */ + 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 JSONArray provided matches the expected JSONArray. If it isn't it throws an @@ -383,9 +692,24 @@ public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean */ public static void assertEquals(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { + assertEquals("", 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 + */ + 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(result.getMessage()); + throw new AssertionError(getCombinedMessage(message, result.getMessage())); } } @@ -400,9 +724,35 @@ public static void assertEquals(JSONArray expected, JSONArray actual, JSONCompar */ public static void assertNotEquals(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { + assertNotEquals("", 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 compareMode Specifies which comparison mode to use + * @throws JSONException + */ + 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(result.getMessage()); + throw new AssertionError(getCombinedMessage(message, result.getMessage())); + } + } + + private static String getCombinedMessage(String message1, String message2) { + String combinedMessage = ""; + + if(message1 == null) { + combinedMessage = message2; + } else { + combinedMessage = message1 + " " + message2; } + return combinedMessage; } } diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java index 65014b68..8060ea4f 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java @@ -1,5 +1,12 @@ package org.skyscreamer.jsonassert; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.skyscreamer.jsonassert.JSONCompareMode.LENIENT; +import static org.skyscreamer.jsonassert.JSONCompareMode.NON_EXTENSIBLE; +import static org.skyscreamer.jsonassert.JSONCompareMode.STRICT; +import static org.skyscreamer.jsonassert.JSONCompareMode.STRICT_ORDER; + import java.util.Arrays; import org.json.JSONArray; @@ -7,8 +14,8 @@ import org.json.JSONObject; import org.junit.Assert; import org.junit.Test; - -import static org.skyscreamer.jsonassert.JSONCompareMode.*; +import org.skyscreamer.jsonassert.comparator.CustomComparator; +import org.skyscreamer.jsonassert.comparator.JSONComparator; /** * Unit tests for {@link JSONAssert} @@ -260,8 +267,8 @@ public void testExpectedObjectButActualArray() throws JSONException { public void testEquivalentIntAndLong() throws JSONException { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); - expected.put("id", new Integer(12345)); - actual.put("id", new Long(12345)); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Long.valueOf(12345)); JSONAssert.assertEquals(expected, actual, true); JSONAssert.assertEquals(actual, expected, true); } @@ -270,8 +277,8 @@ public void testEquivalentIntAndLong() throws JSONException { public void testEquivalentIntAndDouble() throws JSONException { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); - expected.put("id", new Integer(12345)); - actual.put("id", new Double(12345.0)); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12345.0)); JSONAssert.assertEquals(expected, actual, true); JSONAssert.assertEquals(actual, expected, true); } @@ -280,8 +287,8 @@ public void testEquivalentIntAndDouble() throws JSONException { public void testAssertNotEqualsWhenEqualStrict() throws JSONException { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); - expected.put("id", new Integer(12345)); - actual.put("id", new Double(12345)); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12345)); JSONAssert.assertNotEquals(expected, actual, true); } @@ -289,8 +296,8 @@ public void testAssertNotEqualsWhenEqualStrict() throws JSONException { public void testAssertNotEqualsWhenEqualLenient() throws JSONException { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); - expected.put("id", new Integer(12345)); - actual.put("id", new Double(12345)); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12345)); JSONAssert.assertNotEquals(expected, actual, false); } @@ -298,9 +305,9 @@ public void testAssertNotEqualsWhenEqualLenient() throws JSONException { public void testAssertNotEqualsWhenEqualDiffObjectsStrict() throws JSONException { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); - expected.put("id", new Integer(12345)); + expected.put("id", Integer.valueOf(12345)); expected.put("name", "Joe"); - actual.put("id", new Double(12345)); + actual.put("id", Double.valueOf(12345)); JSONAssert.assertNotEquals(expected, actual, true); } @@ -308,10 +315,10 @@ public void testAssertNotEqualsWhenEqualDiffObjectsStrict() throws JSONException public void testAssertNotEqualsWhenEqualDiffObjectsLenient() throws JSONException { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); - expected.put("id", new Integer(12345)); + expected.put("id", Integer.valueOf(12345)); expected.put("name", "Joe"); actual.put("name", "Joe"); - actual.put("id", new Double(12345)); + actual.put("id", Double.valueOf(12345)); JSONAssert.assertNotEquals(expected, actual, false); } @@ -319,8 +326,8 @@ public void testAssertNotEqualsWhenEqualDiffObjectsLenient() throws JSONExceptio public void testAssertNotEqualsWhenDifferentStrict() throws JSONException { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); - expected.put("id", new Integer(12345)); - actual.put("id", new Double(12346)); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12346)); JSONAssert.assertNotEquals(expected, actual, true); } @@ -328,8 +335,8 @@ public void testAssertNotEqualsWhenDifferentStrict() throws JSONException { public void testAssertNotEqualsWhenDifferentLenient() throws JSONException { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); - expected.put("id", new Integer(12345)); - actual.put("id", new Double(12346)); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12346)); JSONAssert.assertNotEquals(expected, actual, false); } @@ -340,11 +347,20 @@ public void testAssertNotEqualsString() throws JSONException { JSONAssert.assertNotEquals("[1,2,3]", "[1,3,2]", true); JSONAssert.assertNotEquals("[1,2,3]", "[1,2,4]", false); } + + @Test() + public void testAssertEqualsString() throws JSONException { + JSONAssert.assertEquals("[1,2,3]", "[1,2,3]", true); + JSONAssert.assertEquals("{id:12345}", "{id:12345}", false); + JSONAssert.assertEquals("{id:12345}", "{id:12345, name:\"john\"}", LENIENT); + JSONAssert.assertEquals("{id:12345}", "{id:12345}", LENIENT); + JSONAssert.assertEquals("{id:12345}", "{id:12345, name:\"john\"}", LENIENT); + } @Test() public void testAssertNotEqualsStringAndJSONObject() throws JSONException { JSONObject actual = new JSONObject(); - actual.put("id", new Double(12345)); + actual.put("id", Double.valueOf(12345)); JSONAssert.assertEquals("{id:12345}", actual, false); JSONAssert.assertNotEquals("{id:12346}", actual, false); } @@ -358,7 +374,132 @@ public void testAssertNotEqualsJSONArray() throws JSONException { JSONAssert.assertNotEquals(new JSONArray(Arrays.asList(1, 2, 4)), actual, false); JSONAssert.assertNotEquals(new JSONArray(Arrays.asList(1, 3, 2)), actual, true); } + + @Test + public void testAssertEqualsStringJSONArrayBooleanWithMessage() throws JSONException { + JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); + JSONAssert.assertEquals("Message", "[1,2,3]", actual, false); + performTestForMessageVerification("[1,2,4]", actual, false); + performTestForMessageVerification("[1,3,2]", actual, true); + } + + @Test + public void testAssertEqualsStringJSONArrayCompareModeWithMessage() throws JSONException { + JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); + JSONAssert.assertEquals("Message", "[1,2,3]", actual, LENIENT); + performTestForMessageVerification("[1,2,4]", actual, LENIENT); + performTestForMessageVerification("[1,3,2]", actual, STRICT); + } + + @Test + public void testAssertEqualsJSONArray2BooleanWithMessage() throws JSONException { + JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); + JSONAssert.assertEquals("Message", new JSONArray(Arrays.asList(1, 2, 3)), actual, false); + performTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 4)), actual, false); + performTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, true); + } + + @Test + public void testAssertEqualsJSONArray2JSONCompareWithMessage() throws JSONException { + JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); + + JSONAssert.assertEquals("Message", new JSONArray(Arrays.asList(1, 2, 3)), actual, LENIENT); + performTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 4)), actual, LENIENT); + performTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, STRICT); + } + + @Test + public void testAssertEqualsString2Boolean() throws JSONException { + JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345}", false); + JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345, name:\"john\"}", false); + + performTestForMessageVerification("{id:12345}", "{id:12345, name:\"john\"}", true); + performTestForMessageVerification("{id:12345}", "{id:123456}", false); + } + + @Test + public void testAssertEqualsString2JSONCompare() throws JSONException { + JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345}", LENIENT); + JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345, name:\"john\"}", LENIENT); + + performTestForMessageVerification("{id:12345}", "{id:12345, name:\"john\"}", STRICT); + performTestForMessageVerification("{id:12345}", "{id:123456}", LENIENT); + } + + @Test + public void testAssertEqualsStringJSONObjectBoolean() throws JSONException { + JSONObject actual = new JSONObject(); + actual.put("id", Double.valueOf(12345)); + JSONAssert.assertEquals("Message", "{id:12345}", actual, false); + performTestForMessageVerification("{id:12346}", actual, false); + performTestForMessageVerification("[1,2,3]", "[1,3,2]", true); + } + + @Test + public void testAssertEqualsStringJSONObjectJSONCompare() throws JSONException { + JSONObject actual = new JSONObject(); + actual.put("id", Double.valueOf(12345)); + JSONAssert.assertEquals("Message", "{id:12345}", actual, LENIENT); + performTestForMessageVerification("{id:12346}", actual, LENIENT); + performTestForMessageVerification("[1,2,3]", "[1,3,2]", STRICT); + } + + @Test + public void testAssertEqualsJSONObject2JSONCompare() throws JSONException { + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", Integer.valueOf(12345)); + actual.put("name", "Joe"); + actual.put("id", Integer.valueOf(12345)); + JSONAssert.assertEquals("Message", expected, actual, LENIENT); + + expected.put("street", "St. Paul"); + performTestForMessageVerification(expected, actual, LENIENT); + + expected = new JSONObject(); + actual = new JSONObject(); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12346)); + performTestForMessageVerification(expected, actual, STRICT); + } + + @Test + public void testAssertEqualsJSONObject2Boolean() throws JSONException { + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", Integer.valueOf(12345)); + actual.put("name", "Joe"); + actual.put("id", Integer.valueOf(12345)); + JSONAssert.assertEquals("Message", expected, actual, false); + + expected.put("street", "St. Paul"); + performTestForMessageVerification(expected, actual, false); + + expected = new JSONObject(); + actual = new JSONObject(); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12346)); + performTestForMessageVerification(expected, actual, true); + } + + @Test + public void testAssertEqualsString2JsonComparator() throws IllegalArgumentException, JSONException { + JSONAssert.assertEquals("Message", "{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":2}}", + new CustomComparator( + JSONCompareMode.STRICT, + new Customization("entry.id", + new RegularExpressionValueMatcher("\\d")) + )); + + performTestForMessageVerification("{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":as}}", + new CustomComparator( + JSONCompareMode.STRICT, + new Customization("entry.id", + new RegularExpressionValueMatcher("\\d")) + )); + } + private void testPass(String expected, String actual, JSONCompareMode compareMode) throws JSONException { @@ -374,4 +515,106 @@ private void testFail(String expected, String actual, JSONCompareMode compareMod JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); Assert.assertTrue(message, result.failed()); } + + private void performTestForMessageVerification(Object expected, Object actual, Object strictMode) throws JSONException { + String message = "Message"; + String testShouldFailMessage = "The test should fail so that the message in AssertionError could be verified."; + String strictModeMessage = "strictMode must be an instance of JSONCompareMode or Boolean"; + boolean assertEqualsFailed = true; + if(expected instanceof String && actual instanceof String && strictMode instanceof JSONComparator) { + try { + JSONAssert.assertEquals(message, (String) expected, (String) actual, (JSONComparator) strictMode); + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } + else if(expected instanceof String && actual instanceof JSONArray) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertEquals(message, (String) expected, (JSONArray) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertEquals(message, (String) expected, (JSONArray) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else if(expected instanceof JSONArray && actual instanceof JSONArray) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertEquals(message, (JSONArray) expected, (JSONArray) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertEquals(message, (JSONArray) expected, (JSONArray) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else if(expected instanceof String && actual instanceof String) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertEquals(message, (String) expected, (String) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertEquals(message, (String) expected, (String) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else if(expected instanceof String && actual instanceof JSONObject) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertEquals(message, (String) expected, (JSONObject) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertEquals(message, (String) expected, (JSONObject) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else if(expected instanceof JSONObject && actual instanceof JSONObject) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertEquals(message, (JSONObject) expected, (JSONObject) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertEquals(message, (JSONObject) expected, (JSONObject) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else { + fail("No overloaded method found to call"); + } + } + + private void handleAssertionError(String message, boolean assertEqualsFailed, AssertionError ae) throws AssertionError { + if(assertEqualsFailed) { + verifyErrorMessage(message, ae); + } else { + throw ae; + } + } + + private void verifyErrorMessage(String message, AssertionError ae) { + assertTrue(ae.getMessage().contains(message)); + assertTrue(ae.getMessage().startsWith(message)); + } } From ac01d2ad1e5e08f92b2a966dafdc894b2a817636 Mon Sep 17 00:00:00 2001 From: yasinb Date: Sat, 18 Mar 2017 09:27:19 +0530 Subject: [PATCH 31/84] JUNit tests for assertNotEquals --- .../jsonassert/JSONAssertTest.java | 273 ++++++++++++++++-- 1 file changed, 249 insertions(+), 24 deletions(-) diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java index 8060ea4f..cfc67176 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java @@ -379,24 +379,24 @@ public void testAssertNotEqualsJSONArray() throws JSONException { public void testAssertEqualsStringJSONArrayBooleanWithMessage() throws JSONException { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("Message", "[1,2,3]", actual, false); - performTestForMessageVerification("[1,2,4]", actual, false); - performTestForMessageVerification("[1,3,2]", actual, true); + performAssertEqualsTestForMessageVerification("[1,2,4]", actual, false); + performAssertEqualsTestForMessageVerification("[1,3,2]", actual, true); } @Test public void testAssertEqualsStringJSONArrayCompareModeWithMessage() throws JSONException { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("Message", "[1,2,3]", actual, LENIENT); - performTestForMessageVerification("[1,2,4]", actual, LENIENT); - performTestForMessageVerification("[1,3,2]", actual, STRICT); + performAssertEqualsTestForMessageVerification("[1,2,4]", actual, LENIENT); + performAssertEqualsTestForMessageVerification("[1,3,2]", actual, STRICT); } - + @Test public void testAssertEqualsJSONArray2BooleanWithMessage() throws JSONException { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("Message", new JSONArray(Arrays.asList(1, 2, 3)), actual, false); - performTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 4)), actual, false); - performTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, true); + performAssertEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 4)), actual, false); + performAssertEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, true); } @Test @@ -404,9 +404,8 @@ public void testAssertEqualsJSONArray2JSONCompareWithMessage() throws JSONExcept JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("Message", new JSONArray(Arrays.asList(1, 2, 3)), actual, LENIENT); - performTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 4)), actual, LENIENT); - performTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, STRICT); - + performAssertEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 4)), actual, LENIENT); + performAssertEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, STRICT); } @Test @@ -414,8 +413,8 @@ public void testAssertEqualsString2Boolean() throws JSONException { JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345}", false); JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345, name:\"john\"}", false); - performTestForMessageVerification("{id:12345}", "{id:12345, name:\"john\"}", true); - performTestForMessageVerification("{id:12345}", "{id:123456}", false); + performAssertEqualsTestForMessageVerification("{id:12345}", "{id:12345, name:\"john\"}", true); + performAssertEqualsTestForMessageVerification("{id:12345}", "{id:123456}", false); } @Test @@ -423,8 +422,8 @@ public void testAssertEqualsString2JSONCompare() throws JSONException { JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345}", LENIENT); JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345, name:\"john\"}", LENIENT); - performTestForMessageVerification("{id:12345}", "{id:12345, name:\"john\"}", STRICT); - performTestForMessageVerification("{id:12345}", "{id:123456}", LENIENT); + performAssertEqualsTestForMessageVerification("{id:12345}", "{id:12345, name:\"john\"}", STRICT); + performAssertEqualsTestForMessageVerification("{id:12345}", "{id:123456}", LENIENT); } @Test @@ -432,8 +431,8 @@ public void testAssertEqualsStringJSONObjectBoolean() throws JSONException { JSONObject actual = new JSONObject(); actual.put("id", Double.valueOf(12345)); JSONAssert.assertEquals("Message", "{id:12345}", actual, false); - performTestForMessageVerification("{id:12346}", actual, false); - performTestForMessageVerification("[1,2,3]", "[1,3,2]", true); + performAssertEqualsTestForMessageVerification("{id:12346}", actual, false); + performAssertEqualsTestForMessageVerification("[1,2,3]", "[1,3,2]", true); } @Test @@ -441,8 +440,8 @@ public void testAssertEqualsStringJSONObjectJSONCompare() throws JSONException { JSONObject actual = new JSONObject(); actual.put("id", Double.valueOf(12345)); JSONAssert.assertEquals("Message", "{id:12345}", actual, LENIENT); - performTestForMessageVerification("{id:12346}", actual, LENIENT); - performTestForMessageVerification("[1,2,3]", "[1,3,2]", STRICT); + performAssertEqualsTestForMessageVerification("{id:12346}", actual, LENIENT); + performAssertEqualsTestForMessageVerification("[1,2,3]", "[1,3,2]", STRICT); } @Test @@ -455,13 +454,13 @@ public void testAssertEqualsJSONObject2JSONCompare() throws JSONException { JSONAssert.assertEquals("Message", expected, actual, LENIENT); expected.put("street", "St. Paul"); - performTestForMessageVerification(expected, actual, LENIENT); + performAssertEqualsTestForMessageVerification(expected, actual, LENIENT); expected = new JSONObject(); actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); actual.put("id", Double.valueOf(12346)); - performTestForMessageVerification(expected, actual, STRICT); + performAssertEqualsTestForMessageVerification(expected, actual, STRICT); } @Test @@ -474,13 +473,13 @@ public void testAssertEqualsJSONObject2Boolean() throws JSONException { JSONAssert.assertEquals("Message", expected, actual, false); expected.put("street", "St. Paul"); - performTestForMessageVerification(expected, actual, false); + performAssertEqualsTestForMessageVerification(expected, actual, false); expected = new JSONObject(); actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); actual.put("id", Double.valueOf(12346)); - performTestForMessageVerification(expected, actual, true); + performAssertEqualsTestForMessageVerification(expected, actual, true); } @Test @@ -492,7 +491,135 @@ public void testAssertEqualsString2JsonComparator() throws IllegalArgumentExcept new RegularExpressionValueMatcher("\\d")) )); - performTestForMessageVerification("{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":as}}", + performAssertEqualsTestForMessageVerification("{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":as}}", + new CustomComparator( + JSONCompareMode.STRICT, + new Customization("entry.id", + new RegularExpressionValueMatcher("\\d")) + )); + } + + @Test + public void testAssertNotEqualsStringJSONArrayBooleanWithMessage() throws JSONException { + JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); + JSONAssert.assertNotEquals("Message", "[1,4,3]", actual, false); + JSONAssert.assertNotEquals("Message", "[1,4,3]", actual, true); + performAssertNotEqualsTestForMessageVerification("[1,3,2]", actual, false); + performAssertNotEqualsTestForMessageVerification("[1,2,3]", actual, true); + } + + @Test + public void testAssertNotEqualsStringJSONArrayCompareModeWithMessage() throws JSONException { + JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); + JSONAssert.assertNotEquals("Message", "[1,2,4]", actual, LENIENT); + JSONAssert.assertNotEquals("Message", "[1,2,4]", actual, STRICT); + performAssertNotEqualsTestForMessageVerification("[1,3,2]", actual, LENIENT); + performAssertNotEqualsTestForMessageVerification("[1,2,3]", actual, STRICT); + } + + @Test + public void testAssertNotEqualsJSONArray2BooleanWithMessage() throws JSONException { + JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); + JSONAssert.assertNotEquals("Message", new JSONArray(Arrays.asList(1, 4, 3)), actual, false); + performAssertNotEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, false); + performAssertNotEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 3)), actual, true); + } + + @Test + public void testAssertNotEqualsJSONArray2JSONCompareWithMessage() throws JSONException { + JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); + + JSONAssert.assertNotEquals("Message", new JSONArray(Arrays.asList(1, 4, 3)), actual, LENIENT); + performAssertNotEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, LENIENT); + performAssertNotEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 3)), actual, STRICT); + } + + @Test + public void testAssertNotEqualsString2Boolean() throws JSONException { + JSONAssert.assertNotEquals("Message", "{id:12345}", "{id:45}", false); + JSONAssert.assertNotEquals("Message", "{id:12345}", "{id:345, name:\"john\"}", false); + + performAssertNotEqualsTestForMessageVerification("{id:12345}", "{id:12345}", true); + performAssertNotEqualsTestForMessageVerification("{id:12345}", "{id:12345, name:\"John\"}", false); + } + + @Test + public void testAssertNotEqualsString2JSONCompare() throws JSONException { + JSONAssert.assertNotEquals("Message", "{id:12345}", "{id:123}", LENIENT); + JSONAssert.assertNotEquals("Message", "{id:12345, name:\"John\"}", "{id:12345}", LENIENT); + + performAssertNotEqualsTestForMessageVerification("{id:12345}", "{id:12345, name:\"john\"}", LENIENT); + performAssertNotEqualsTestForMessageVerification("{id:12345}", "{id:12345}", STRICT); + } + + @Test + public void testAssertNotEqualsStringJSONObjectBoolean() throws JSONException { + JSONObject actual = new JSONObject(); + actual.put("id", Double.valueOf(12345)); + JSONAssert.assertNotEquals("Message", "{id:1234}", actual, false); + performAssertNotEqualsTestForMessageVerification("{id:12345}", actual, false); + performAssertNotEqualsTestForMessageVerification("[1,2,3]", "[1,2,3]", true); + } + + @Test + public void testAssertNotEqualsStringJSONObjectJSONCompare() throws JSONException { + JSONObject actual = new JSONObject(); + actual.put("id", Double.valueOf(12345)); + JSONAssert.assertNotEquals("Message", "{id:1234}", actual, LENIENT); + performAssertNotEqualsTestForMessageVerification("{id:12345}", actual, LENIENT); + performAssertNotEqualsTestForMessageVerification("[1,2,3]", "[1,2,3]", STRICT); + } + + @Test + public void testAssertNtEqualsJSONObject2JSONCompare() throws JSONException { + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", Integer.valueOf(12345)); + actual.put("name", "Joe"); + actual.put("id", Integer.valueOf(123)); + JSONAssert.assertNotEquals("Message", expected, actual, LENIENT); + + actual.remove("id"); + actual.put("id", Integer.valueOf(12345)); + performAssertNotEqualsTestForMessageVerification(expected, actual, LENIENT); + + expected = new JSONObject(); + actual = new JSONObject(); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12345)); + performAssertNotEqualsTestForMessageVerification(expected, actual, STRICT); + } + + @Test + public void testAssertNotEqualsJSONObject2Boolean() throws JSONException { + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", Integer.valueOf(12345)); + actual.put("name", "Joe"); + actual.put("id", Integer.valueOf(123)); + JSONAssert.assertNotEquals("Message", expected, actual, false); + + actual.remove("id"); + actual.put("id", Integer.valueOf(12345)); + performAssertNotEqualsTestForMessageVerification(expected, actual, false); + + expected = new JSONObject(); + actual = new JSONObject(); + expected.put("id", Integer.valueOf(12345)); + actual.put("id", Double.valueOf(12345)); + performAssertNotEqualsTestForMessageVerification(expected, actual, true); + } + + @Test + public void testAssertNotEqualsString2JsonComparator() throws IllegalArgumentException, JSONException { + JSONAssert.assertNotEquals("Message", "{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":hh}}", + new CustomComparator( + JSONCompareMode.STRICT, + new Customization("entry.id", + new RegularExpressionValueMatcher("\\d")) + )); + + performAssertNotEqualsTestForMessageVerification("{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":2}}", new CustomComparator( JSONCompareMode.STRICT, new Customization("entry.id", @@ -516,7 +643,11 @@ private void testFail(String expected, String actual, JSONCompareMode compareMod Assert.assertTrue(message, result.failed()); } - private void performTestForMessageVerification(Object expected, Object actual, Object strictMode) throws JSONException { + private void performAssertEqualsTestForMessageVerification( + Object expected, + Object actual, + Object strictMode) throws JSONException { + String message = "Message"; String testShouldFailMessage = "The test should fail so that the message in AssertionError could be verified."; String strictModeMessage = "strictMode must be an instance of JSONCompareMode or Boolean"; @@ -604,6 +735,100 @@ else if(expected instanceof String && actual instanceof JSONArray) { fail("No overloaded method found to call"); } } + + private void performAssertNotEqualsTestForMessageVerification( + Object expected, + Object actual, + Object strictMode) + throws JSONException { + + String message = "Message"; + String testShouldFailMessage = "The test should fail so that the message in AssertionError could be verified."; + String strictModeMessage = "strictMode must be an instance of JSONCompareMode or Boolean"; + boolean assertEqualsFailed = true; + if(expected instanceof String && actual instanceof String && strictMode instanceof JSONComparator) { + try { + JSONAssert.assertNotEquals(message, (String) expected, (String) actual, (JSONComparator) strictMode); + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } + else if(expected instanceof String && actual instanceof JSONArray) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertNotEquals(message, (String) expected, (JSONArray) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertNotEquals(message, (String) expected, (JSONArray) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else if(expected instanceof JSONArray && actual instanceof JSONArray) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertNotEquals(message, (JSONArray) expected, (JSONArray) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertNotEquals(message, (JSONArray) expected, (JSONArray) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else if(expected instanceof String && actual instanceof String) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertNotEquals(message, (String) expected, (String) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertNotEquals(message, (String) expected, (String) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else if(expected instanceof String && actual instanceof JSONObject) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertNotEquals(message, (String) expected, (JSONObject) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertNotEquals(message, (String) expected, (JSONObject) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else if(expected instanceof JSONObject && actual instanceof JSONObject) { + try { + if(strictMode instanceof JSONCompareMode) { + JSONAssert.assertNotEquals(message, (JSONObject) expected, (JSONObject) actual, (JSONCompareMode) strictMode); + } else if(strictMode instanceof Boolean) { + JSONAssert.assertNotEquals(message, (JSONObject) expected, (JSONObject) actual, (Boolean) strictMode); + } else { + fail(strictModeMessage); + } + assertEqualsFailed = false; + fail(testShouldFailMessage); //will throw AssertionError + } catch (AssertionError ae) { + handleAssertionError(message, assertEqualsFailed, ae); + } + } else { + fail("No overloaded method found to call"); + } + } private void handleAssertionError(String message, boolean assertEqualsFailed, AssertionError ae) throws AssertionError { if(assertEqualsFailed) { From 902e4badf269040b44c1bced6a2f02b241c6cac6 Mon Sep 17 00:00:00 2001 From: yasinb Date: Sun, 19 Mar 2017 09:18:49 +0530 Subject: [PATCH 32/84] Fixes broken tests The broken tests by the original PR are fixed now - ArrayValueMatcherTest.txt - ArraySizeComparatorTest.txt --- src/main/java/org/skyscreamer/jsonassert/JSONAssert.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java index a243a3c3..ff32c19e 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java @@ -748,7 +748,7 @@ public static void assertNotEquals(String message, JSONArray expected, JSONArray private static String getCombinedMessage(String message1, String message2) { String combinedMessage = ""; - if(message1 == null) { + if(message1 == null || "".equals(message1)) { combinedMessage = message2; } else { combinedMessage = message1 + " " + message2; From 8bf08ec3b9c978bc9b446206dd2ddf6be4b48099 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 13:32:26 -0400 Subject: [PATCH 33/84] Updating version #s to prepare for new release. --- CHANGELOG.md | 5 +++++ README.md | 2 +- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a277cef1..de842255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Changelog ========= +Version 1.5.0 - 3/19/2017 +------------------------- + - JSONassert now supports user-supplied error messages (thanks yasin3061@!) + - Some refactoring / code health cleanup (thanks picimako@!) + Version 1.4.0 - 10/30/2016 -------------------------- - Change the implementation for org.json to one with a more open license diff --git a/README.md b/README.md index 77a83ce6..c28ba6de 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert - 1.4.0 + 1.5.0 test diff --git a/src/site/resources/index.html b/src/site/resources/index.html index 89c584e0..98d14384 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

    Introduction

  • JUnit
  • -


    The current version of JSONassert is 1.4.0

    +


    The current version of JSONassert is 1.5.0

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index ddcb7f91..67f7e637 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>1.4.0</version>
    +   <version>1.5.0</version>
    </dependency>
    From 7fa08cc8d3951c939e9787d09f81f3dfb3c345f3 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 17:25:22 -0400 Subject: [PATCH 34/84] Fixed javadocs to be JDK 8 compatible. --- CHANGELOG.md | 8 +- src/main/java/org/json/JSONString.java | 2 + .../jsonassert/ArrayValueMatcher.java | 105 ++++++++++-------- .../skyscreamer/jsonassert/JSONAssert.java | 90 +++++++-------- .../skyscreamer/jsonassert/JSONCompare.java | 16 ++- .../jsonassert/JSONCompareMode.java | 4 +- .../jsonassert/JSONCompareResult.java | 24 +++- .../skyscreamer/jsonassert/JSONParser.java | 2 +- .../comparator/AbstractComparator.java | 6 +- .../comparator/DefaultComparator.java | 2 +- .../jsonassert/comparator/JSONComparator.java | 10 +- .../comparator/JSONCompareUtil.java | 27 +++-- 12 files changed, 173 insertions(+), 123 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index de842255..8e48f61a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,16 +14,16 @@ Version 1.4.0 - 10/30/2016 Version 1.3.0 - 12/16/2015 -------------------------- - - Fix & improve ArrayValueMatcher JavaDoc (dmackinder) + - Fix & improve ArrayValueMatcher JavaDoc (thanks dmackinder!) Fix final JavaDoc example and add new example showing how to verify every array element using a custom comparator - Fix URL in pom.xml (aukevanleeuwen) - - Update JSONCompareResult.java adding 2 new lists for missing and unexpected fileds (riccorazza) - - Includes missing imports in test class (javierseixas) + - Update JSONCompareResult.java adding 2 new lists for missing and unexpected fileds (thanks riccorazza!) + - Includes missing imports in test class (thanks javierseixas!) Version 1.2.3 - 2/5/2014 ------------------------ - - This edition brought to you by dmackinder (thanks!) + - This edition brought to you by dmackinder (thanks dmackinder!) - Added array size comparator enhancements. - Added ArrayValueMatcher to simplify verification of range of array elements. - Improve diagnostics from RegularExpressionValueMatcher. diff --git a/src/main/java/org/json/JSONString.java b/src/main/java/org/json/JSONString.java index 6ba68fa7..2d6c52c8 100644 --- a/src/main/java/org/json/JSONString.java +++ b/src/main/java/org/json/JSONString.java @@ -14,6 +14,8 @@ public interface JSONString { /** * The toJSONString method allows a class to produce its own JSON * serialization. + * + * @return String representation of JSON object * */ String toJSONString(); diff --git a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java index ddc849de..8bb39a61 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java @@ -22,62 +22,73 @@ * *

    Assuming JSON to be verified is held in String variable ARRAY_OF_JSONOBJECTS and contains:

    * - * {a:[{background:white,id:1,type:row}, {background:grey,id:2,type:row}, {background:white,id:3,type:row}, {background:grey,id:4,type:row}]} + *
    {@code
    + * {a:[{background:white, id:1, type:row},
    + *     {background:grey,  id:2, type:row},
    + *     {background:white, id:3, type:row},
    + *     {background:grey,  id:4, type:row}]}
    + * }
    * *

    then:

    * *

    To verify that the 'id' attribute of first element of array 'a' is '1':

    * - * - * JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
    - * Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 0));
    - * JSONAssert.assertEquals("{a:[{id:1}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); - *
    + *
    {@code
    + * JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
    + * Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 0));
    + * JSONAssert.assertEquals("{a:[{id:1}]}", ARRAY_OF_JSONOBJECTS,
    + *     new CustomComparator(JSONCompareMode.LENIENT, customization));
    + * }
      *
      * 

    To simplify complexity of expected JSON string, the value "a:[{id:1}]}" may be replaced by "a:{id:1}}"

    * *

    To verify that the 'type' attribute of second and third elements of array 'a' is 'row':

    * - * - * JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
    - * Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 1, 2));
    - * JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); - *
    + *
    {@code
    + * JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
    + * Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 1, 2));
    + * JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS,
    + *     new CustomComparator(JSONCompareMode.LENIENT, customization));
    + * }
      * 
      * 

    To verify that the 'type' attribute of every element of array 'a' is 'row':

    * - * - * JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
    - * Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator));
    - * JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); - *
    + *
    {@code
    + * JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
    + * Customization customization = new Customization("a", new ArrayValueMatcher(comparator));
    + * JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS,
    + *     new CustomComparator(JSONCompareMode.LENIENT, customization));
    + * }
      * 
      * 

    To verify that the 'id' attribute of every element of array 'a' matches regular expression '\d+'. This requires a custom comparator to specify regular expression to be used to validate each array element, hence the array of Customization instances:

    * - * - * // get length of array we will verify
    - * int aLength = ((JSONArray)((JSONObject)JSONParser.parseJSON(ARRAY_OF_JSONOBJECTS)).get("a")).length();
    - * // create array of customizations one for each array element
    - * RegularExpressionValueMatcher<Object> regExValueMatcher = new RegularExpressionValueMatcher<Object>("\\d+"); // matches one or more digits
    - * Customization[] customizations = new Customization[aLength];
    - * for (int i=0; i<aLength; i++) {
    - *   String contextPath = "a["+i+"].id";
    - *   customizations[i] = new Customization(contextPath, regExValueMatcher);
    - * }
    - * CustomComparator regExComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, customizations);
    - * ArrayValueMatcher<Object> regExArrayValueMatcher = new ArrayValueMatcher<Object>(regExComparator);
    - * Customization regExArrayValueCustomization = new Customization("a", regExArrayValueMatcher);
    - * CustomComparator regExCustomArrayValueComparator = new CustomComparator(JSONCompareMode.STRICT_ORDER, new Customization[] { regExArrayValueCustomization });
    - * JSONAssert.assertEquals("{a:[{id:X}]}", ARRAY_OF_JSONOBJECTS, regExCustomArrayValueComparator);
    - *
    + *
    {@code
    + * // get length of array we will verify
    + * int aLength = ((JSONArray)((JSONObject)JSONParser.parseJSON(ARRAY_OF_JSONOBJECTS)).get("a")).length();
    + * // create array of customizations one for each array element
    + * RegularExpressionValueMatcher regExValueMatcher =
    + *     new RegularExpressionValueMatcher("\\d+");  // matches one or more digits
    + * Customization[] customizations = new Customization[aLength];
    + * for (int i=0; i regExArrayValueMatcher = new ArrayValueMatcher(regExComparator);
    + * Customization regExArrayValueCustomization = new Customization("a", regExArrayValueMatcher);
    + * CustomComparator regExCustomArrayValueComparator =
    + *     new CustomComparator(JSONCompareMode.STRICT_ORDER, new Customization[] { regExArrayValueCustomization });
    + * JSONAssert.assertEquals("{a:[{id:X}]}", ARRAY_OF_JSONOBJECTS, regExCustomArrayValueComparator);
    + * }
      * 
      * 

    To verify that the 'background' attribute of every element of array 'a' alternates between 'white' and 'grey' starting with first element 'background' being 'white':

    * - * - * JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
    - * Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator));
    - * JSONAssert.assertEquals("{a:[{background:white},{background:grey}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); - *
    + *
    {@code
    + * JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
    + * Customization customization = new Customization("a", new ArrayValueMatcher(comparator));
    + * JSONAssert.assertEquals("{a:[{background:white},{background:grey}]}", ARRAY_OF_JSONOBJECTS,
    + *     new CustomComparator(JSONCompareMode.LENIENT, customization));
    + * }
      * 
      * 

    Assuming JSON to be verified is held in String variable ARRAY_OF_JSONARRAYS and contains:

    * @@ -87,23 +98,23 @@ * *

    To verify that the first three elements of JSON array 'a' are JSON arrays of length 3:

    * - * - * JSONComparator comparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER);
    - * Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 0, 2));
    + *
    {@code
    + * JSONComparator comparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER);
    + * Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 0, 2));
      * JSONAssert.assertEquals("{a:[[3]]}", ARRAY_OF_JSONARRAYS, new CustomComparator(JSONCompareMode.LENIENT, customization));
    - * 
    + * }
      *
      * 

    NOTE: simplified expected JSON strings are not possible in this case as ArraySizeComparator does not support them.

    * *

    To verify that the second elements of JSON array 'a' is a JSON array whose first element has the value 9:

    * - * - * JSONComparator innerComparator = new DefaultComparator(JSONCompareMode.LENIENT);
    - * Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher<Object>(innerComparator, 0));
    - * JSONComparator comparator = new CustomComparator(JSONCompareMode.LENIENT, innerCustomization);
    - * Customization customization = new Customization("a", new ArrayValueMatcher<Object>(comparator, 1));
    + *
    {@code
    + * JSONComparator innerComparator = new DefaultComparator(JSONCompareMode.LENIENT);
    + * Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher(innerComparator, 0));
    + * JSONComparator comparator = new CustomComparator(JSONCompareMode.LENIENT, innerCustomization);
    + * Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 1));
      * JSONAssert.assertEquals("{a:[[9]]}", ARRAY_OF_JSONARRAYS, new CustomComparator(JSONCompareMode.LENIENT, customization));
    - * 
    + * }
      *
      * 

    To simplify complexity of expected JSON string, the value "{a:[[9]]}" may be replaced by "{a:[9]}" or "{a:9}"

    * diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java index ca78c10e..553ba7e6 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java @@ -45,7 +45,7 @@ private JSONAssert() {} * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String expectedStr, JSONObject actual, boolean strict) throws JSONException { @@ -60,7 +60,7 @@ public static void assertEquals(String expectedStr, JSONObject actual, boolean s * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, JSONObject actual, boolean strict) throws JSONException { @@ -76,7 +76,7 @@ public static void assertEquals(String message, String expectedStr, JSONObject a * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, JSONObject actual, boolean strict) throws JSONException { @@ -87,13 +87,13 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, boolea * Asserts that the JSONObject provided does not match the expected string. If it is it throws an * {@link AssertionError}. * - * @see #assertEquals(String JSONObject, boolean) + * @see #assertEquals(String, JSONObject, boolean) * * @param message Error message to be displayed in case of assertion failure * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, JSONObject actual, boolean strict) throws JSONException { @@ -107,7 +107,7 @@ public static void assertNotEquals(String message, String expectedStr, JSONObjec * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) throws JSONException { @@ -122,7 +122,7 @@ public static void assertEquals(String expectedStr, JSONObject actual, JSONCompa * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, JSONObject actual, JSONCompareMode compareMode) throws JSONException { @@ -144,7 +144,7 @@ public static void assertEquals(String message, String expectedStr, JSONObject a * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) throws JSONException { @@ -161,7 +161,7 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCo * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, JSONObject actual, JSONCompareMode compareMode) throws JSONException { @@ -181,7 +181,7 @@ public static void assertNotEquals(String message, String expectedStr, JSONObjec * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String expectedStr, JSONArray actual, boolean strict) throws JSONException { @@ -196,7 +196,7 @@ public static void assertEquals(String expectedStr, JSONArray actual, boolean st * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, JSONArray actual, boolean strict) throws JSONException { @@ -210,7 +210,7 @@ public static void assertEquals(String message, String expectedStr, JSONArray ac * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, JSONArray actual, boolean strict) throws JSONException { @@ -225,7 +225,7 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, boolean * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, JSONArray actual, boolean strict) throws JSONException { @@ -239,7 +239,7 @@ public static void assertNotEquals(String message, String expectedStr, JSONArray * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String expectedStr, JSONArray actual, JSONCompareMode compareMode) throws JSONException { @@ -254,7 +254,7 @@ public static void assertEquals(String expectedStr, JSONArray actual, JSONCompar * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, JSONArray actual, JSONCompareMode compareMode) throws JSONException { @@ -274,7 +274,7 @@ public static void assertEquals(String message, String expectedStr, JSONArray ac * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCompareMode compareMode) throws JSONException { @@ -295,7 +295,7 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCom * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, JSONArray actual, JSONCompareMode compareMode) throws JSONException { @@ -315,7 +315,7 @@ public static void assertNotEquals(String message, String expectedStr, JSONArray * @param expectedStr Expected JSON string * @param actualStr String to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String expectedStr, String actualStr, boolean strict) throws JSONException { @@ -330,7 +330,7 @@ public static void assertEquals(String expectedStr, String actualStr, boolean st * @param expectedStr Expected JSON string * @param actualStr String to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, String actualStr, boolean strict) throws JSONException { @@ -344,7 +344,7 @@ public static void assertEquals(String message, String expectedStr, String actua * @param expectedStr Expected JSON string * @param actualStr String to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, String actualStr, boolean strict) throws JSONException { @@ -359,7 +359,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, boolean * @param expectedStr Expected JSON string * @param actualStr String to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, String actualStr, boolean strict) throws JSONException { @@ -373,7 +373,7 @@ public static void assertNotEquals(String message, String expectedStr, String ac * @param expectedStr Expected JSON string * @param actualStr String to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String expectedStr, String actualStr, JSONCompareMode compareMode) throws JSONException { @@ -388,7 +388,7 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar * @param expectedStr Expected JSON string * @param actualStr String to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, String actualStr, JSONCompareMode compareMode) throws JSONException { @@ -411,7 +411,7 @@ public static void assertEquals(String message, String expectedStr, String actua * @param expectedStr Expected JSON string * @param actualStr String to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, String actualStr, JSONCompareMode compareMode) throws JSONException { @@ -426,7 +426,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom * @param expectedStr Expected JSON string * @param actualStr String to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, String actualStr, JSONCompareMode compareMode) throws JSONException { @@ -443,7 +443,7 @@ public static void assertNotEquals(String message, String expectedStr, String ac * @param expectedStr Expected JSON string * @param actualStr String to compare * @param comparator Comparator - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { @@ -459,7 +459,7 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar * @param expectedStr Expected JSON string * @param actualStr String to compare * @param comparator Comparator - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { @@ -476,7 +476,7 @@ public static void assertEquals(String message, String expectedStr, String actua * @param expectedStr Expected JSON string * @param actualStr String to compare * @param comparator Comparator - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { @@ -491,7 +491,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom * @param expectedStr Expected JSON string * @param actualStr String to compare * @param comparator Comparator - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, String expectedStr, String actualStr, JSONComparator comparator) throws JSONException { @@ -508,7 +508,7 @@ public static void assertNotEquals(String message, String expectedStr, String ac * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(JSONObject expected, JSONObject actual, boolean strict) throws JSONException { @@ -523,7 +523,7 @@ public static void assertEquals(JSONObject expected, JSONObject actual, boolean * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, JSONObject expected, JSONObject actual, boolean strict) throws JSONException { @@ -537,7 +537,7 @@ public static void assertEquals(String message, JSONObject expected, JSONObject * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(JSONObject expected, JSONObject actual, boolean strict) throws JSONException { @@ -552,7 +552,7 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, boole * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, JSONObject expected, JSONObject actual, boolean strict) throws JSONException { @@ -566,7 +566,7 @@ public static void assertNotEquals(String message, JSONObject expected, JSONObje * @param expected Expected JSONObject * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(JSONObject expected, JSONObject actual, JSONCompareMode compareMode) throws JSONException { @@ -581,7 +581,7 @@ public static void assertEquals(JSONObject expected, JSONObject actual, JSONComp * @param expected Expected JSONObject * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, JSONObject expected, JSONObject actual, JSONCompareMode compareMode) throws JSONException { @@ -598,7 +598,7 @@ public static void assertEquals(String message, JSONObject expected, JSONObject * @param expected Expected JSONObject * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONCompareMode compareMode) throws JSONException { @@ -613,7 +613,7 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONC * @param expected Expected JSONObject * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, JSONObject expected, JSONObject actual, JSONCompareMode compareMode) throws JSONException { @@ -630,7 +630,7 @@ public static void assertNotEquals(String message, JSONObject expected, JSONObje * @param expected Expected JSONArray * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(JSONArray expected, JSONArray actual, boolean strict) throws JSONException { @@ -645,7 +645,7 @@ public static void assertEquals(JSONArray expected, JSONArray actual, boolean st * @param expected Expected JSONArray * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, JSONArray expected, JSONArray actual, boolean strict) throws JSONException { @@ -659,7 +659,7 @@ public static void assertEquals(String message, JSONArray expected, JSONArray ac * @param expected Expected JSONArray * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean strict) throws JSONException { @@ -674,7 +674,7 @@ public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean * @param expected Expected JSONArray * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, JSONArray expected, JSONArray actual, boolean strict) throws JSONException { @@ -688,7 +688,7 @@ public static void assertNotEquals(String message, JSONArray expected, JSONArray * @param expected Expected JSONArray * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { @@ -703,7 +703,7 @@ public static void assertEquals(JSONArray expected, JSONArray actual, JSONCompar * @param expected Expected JSONArray * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertEquals(String message, JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { @@ -720,7 +720,7 @@ public static void assertEquals(String message, JSONArray expected, JSONArray ac * @param expected Expected JSONArray * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { @@ -735,7 +735,7 @@ public static void assertNotEquals(JSONArray expected, JSONArray actual, JSONCom * @param expected Expected JSONArray * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException + * @throws JSONException JSON parsing error */ public static void assertNotEquals(String message, JSONArray expected, JSONArray actual, JSONCompareMode compareMode) throws JSONException { diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java index fc41bf4f..6a731639 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java @@ -27,7 +27,7 @@ private static JSONComparator getComparatorForMode(JSONCompareMode mode) { * @param actualStr JSON string to compare * @param comparator Comparator to use * @return result of the comparison - * @throws JSONException + * @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) @@ -58,7 +58,7 @@ else if (expected instanceof JSONObject) { * @param actual actual json object * @param comparator comparator to use * @return result of the comparison - * @throws JSONException + * @throws JSONException JSON parsing error */ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONComparator comparator) throws JSONException { @@ -72,7 +72,7 @@ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actu * @param actual actual json array * @param comparator comparator to use * @return result of the comparison - * @throws JSONException + * @throws JSONException JSON parsing error */ public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONComparator comparator) throws JSONException { @@ -85,6 +85,7 @@ public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual * * @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(); @@ -102,7 +103,8 @@ public static JSONCompareResult compareJson(final JSONString expected, final JSO * @param expectedStr Expected JSON string * @param actualStr JSON string to compare * @param mode Defines comparison behavior - * @throws JSONException + * @return result of the comparison + * @throws JSONException JSON parsing error */ public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONCompareMode mode) throws JSONException { @@ -115,7 +117,8 @@ public static JSONCompareResult compareJSON(String expectedStr, String actualStr * @param expected Expected JSONObject * @param actual JSONObject to compare * @param mode Defines comparison behavior - * @throws JSONException + * @return result of the comparison + * @throws JSONException JSON parsing error */ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONCompareMode mode) throws JSONException { @@ -129,7 +132,8 @@ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actu * @param expected Expected JSONArray * @param actual JSONArray to compare * @param mode Defines comparison behavior - * @throws JSONException + * @return result of the comparison + * @throws JSONException JSON parsing error */ public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONCompareMode mode) throws JSONException { diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java index 849e1cab..84ac7824 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java @@ -4,7 +4,7 @@ *

    These different modes define different behavior for the comparison of JSON for testing. * Each mode encapsulates two underlying behaviors: extensibility and strict ordering.

    * - * + *
    * * * @@ -76,6 +76,7 @@ public boolean hasStrictOrder() { /** * Get the equivalent {@code JSONCompareMode} with or without strict ordering. * + * @param strictOrdering if true, requires strict ordering of array elements * @return the equivalent {@code JSONCompareMode} */ public JSONCompareMode withStrictOrdering(boolean strictOrdering) { @@ -89,6 +90,7 @@ public JSONCompareMode withStrictOrdering(boolean strictOrdering) { /** * Get the equivalent {@code JSONCompareMode} with or without extensibility. * + * @param extensible if true, allows keys in actual that don't appear in expected * @return the equivalent {@code JSONCompareMode} */ public JSONCompareMode withExtensible(boolean extensible) { diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java index 2cf7cad9..9d521f87 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java @@ -58,6 +58,7 @@ public String getMessage() { /** * Get the list of failures on field comparisons + * @return list of comparsion failures */ public List getFieldFailures() { return Collections.unmodifiableList(_fieldFailures); @@ -65,6 +66,7 @@ public List getFieldFailures() { /** * Get the list of missed on field comparisons + * @return list of comparsion failures */ public List getFieldMissing() { return Collections.unmodifiableList(_fieldMissing); @@ -72,6 +74,7 @@ public List getFieldMissing() { /** * Get the list of failures on field comparisons + * @return list of comparsion failures */ public List getFieldUnexpected() { return Collections.unmodifiableList(_fieldUnexpected); @@ -105,6 +108,7 @@ public Object getExpected() { /** * Check if comparison failed on any particular fields + * @return true if there are field failures */ public boolean isFailureOnField() { return !_fieldFailures.isEmpty(); @@ -112,6 +116,7 @@ public boolean isFailureOnField() { /** * Check if comparison failed with missing on any particular fields + * @return true if an expected field is missing */ public boolean isMissingOnField() { return !_fieldMissing.isEmpty(); @@ -119,6 +124,7 @@ public boolean isMissingOnField() { /** * Check if comparison failed with unexpected on any particular fields + * @return true if an unexpected field is in the result */ public boolean isUnexpectedOnField() { return !_fieldUnexpected.isEmpty(); @@ -150,6 +156,7 @@ public void fail(String message) { * @param field Which field failed * @param expected Expected result * @param actual Actual result + * @return result of comparision */ public JSONCompareResult fail(String field, Object expected, Object actual) { _fieldFailures.add(new FieldComparisonFailure(field, expected, actual)); @@ -164,6 +171,7 @@ public JSONCompareResult fail(String field, Object expected, Object actual) { * Identify that the comparison failed * @param field Which field failed * @param exception exception containing details of match failure + * @return result of comparision */ public JSONCompareResult fail(String field, ValueMatcherException exception) { fail(field + ": " + exception.getMessage(), exception.getExpected(), exception.getActual()); @@ -179,6 +187,12 @@ private String formatFailureMessage(String field, Object expected, Object actual + "\n"; } + /** + * Identify the missing field + * @param field missing field + * @param expected expected result + * @return result of comparison + */ public JSONCompareResult missing(String field, Object expected) { _fieldMissing.add(new FieldComparisonFailure(field, expected, null)); fail(formatMissing(field, expected)); @@ -192,13 +206,19 @@ private String formatMissing(String field, Object expected) { + "\n but none found\n"; } - public JSONCompareResult unexpected(String field, Object value) { + /** + * Identify unexpected field + * @param field unexpected field + * @param actual actual result + * @return result of comparison + */ + public JSONCompareResult unexpected(String field, Object actual) { _fieldUnexpected.add(new FieldComparisonFailure(field, null, value)); fail(formatUnexpected(field, value)); return this; } - private String formatUnexpected(String field, Object value) { + private String formatUnexpected(String field, Object actual) { return field + "\nUnexpected: " + describe(value) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONParser.java b/src/main/java/org/skyscreamer/jsonassert/JSONParser.java index 45df77c1..ae62922a 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONParser.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONParser.java @@ -22,7 +22,7 @@ private JSONParser() {} * * @param s Raw JSON string to be parsed * @return JSONObject or JSONArray - * @throws JSONException + * @throws JSONException JSON parsing error */ public static Object parseJSON(final String s) throws JSONException { if (s.trim().startsWith("{")) { diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java index 037bb6af..04b7638f 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java @@ -11,7 +11,7 @@ /** * This class provides a skeletal implementation of the {@link JSONComparator} - * interface, to minimize the effort required to implement this interface.

    + * interface, to minimize the effort required to implement this interface. */ public abstract class AbstractComparator implements JSONComparator { @@ -20,7 +20,7 @@ public abstract class AbstractComparator implements JSONComparator { * * @param expected Expected JSONObject * @param actual JSONObject to compare - * @throws JSONException + * @throws JSONException JSON parsing error */ @Override public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) throws JSONException { @@ -34,7 +34,7 @@ public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actua * * @param expected Expected JSONArray * @param actual JSONArray to compare - * @throws JSONException + * @throws JSONException JSON parsing error */ @Override public final JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) throws JSONException { diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java index 74ce8146..b757040b 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java @@ -10,7 +10,7 @@ import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allSimpleValues; /** - * This class is the default json comparator implementation.

    + * This class is the default json comparator implementation. * Comparison is performed according to {@link JSONCompareMode} that is passed as constructor's argument. */ public class DefaultComparator extends AbstractComparator { diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java index 0574e0fe..e15e14fd 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java @@ -19,7 +19,7 @@ public interface JSONComparator { * @param expected the expected JSON object * @param actual the actual JSON object * @return the result of the comparison - * @throws JSONException + * @throws JSONException JSON parsing error */ JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) throws JSONException; @@ -29,7 +29,7 @@ public interface JSONComparator { * @param expected the expected JSON array * @param actual the actual JSON array * @return the result of the comparison - * @throws JSONException + * @throws JSONException JSON parsing error */ JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) throws JSONException; @@ -41,7 +41,7 @@ public interface JSONComparator { * @param expected the expected JSON object * @param actual the actual JSON object * @param result stores the actual state of the comparison result - * @throws JSONException + * @throws JSONException JSON parsing error */ void compareJSON(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) throws JSONException; @@ -53,7 +53,7 @@ public interface JSONComparator { * @param expectedValue the expected value * @param actualValue the actual value * @param result stores the actual state of the comparison result - * @throws JSONException + * @throws JSONException JSON parsing error */ void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException; @@ -65,7 +65,7 @@ public interface JSONComparator { * @param expected the expected JSON array * @param actual the actual JSON array * @param result stores the actual state of the comparison result - * @throws JSONException + * @throws JSONException JSON parsing error */ void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException; } diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java index 273c8161..82eee90b 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java @@ -30,7 +30,7 @@ private JSONCompareUtil() { * @param array the JSON array to convert * @param uniqueKey the key to map the JSON objects to * @return the map of {@link JSONObject}s from {@code array} - * @throws JSONException + * @throws JSONException JSON parsing error */ public static Map arrayOfJsonObjectToMap(JSONArray array, String uniqueKey) throws JSONException { Map valueMap = new HashMap(); @@ -47,7 +47,7 @@ public static Map arrayOfJsonObjectToMap(JSONArray array, St * * @param expected the array to find the unique key of * @return the unique key if there's any, otherwise null - * @throws JSONException + * @throws JSONException JSON parsing error */ public static String findUniqueKey(JSONArray expected) throws JSONException { // Find a unique key for the object (id, name, whatever) @@ -60,8 +60,19 @@ public static String findUniqueKey(JSONArray expected) throws JSONException { } /** - * {@code candidate} is usable as a unique key if every element in the - * {@code array} is a JSONObject having that key, and no two values are the same. + *

    Looks to see if candidate field is a possible unique key across a array of objects. + * Returns true IFF:

    + *
      + *
    1. array is an array of JSONObject + *
    2. candidate is a top-level field in each of of the objects in the array + *
    3. candidate is a simple value (not JSONObject or JSONArray) + *
    4. candidate is unique across all elements in the array + *
    + * + * @param candidate is usable as a unique key if every element in the + * @param array is a JSONObject having that key, and no two values are the same. + * @return true if the candidate can work as a unique id across array + * @throws JSONException JSON parsing error */ public static boolean isUsableAsUniqueKey(String candidate, JSONArray array) throws JSONException { Set seenValues = new HashSet(); @@ -91,7 +102,7 @@ public static boolean isUsableAsUniqueKey(String candidate, JSONArray array) thr * * @param expected the JSON array to convert * @return the list of objects from the {@code expected} array - * @throws JSONException + * @throws JSONException JSON parsing error */ public static List jsonArrayToList(JSONArray expected) throws JSONException { List jsonObjects = new ArrayList(expected.length()); @@ -106,7 +117,7 @@ public static List jsonArrayToList(JSONArray expected) throws JSONExcept * * @param array the JSON array to iterate through on * @return true if all the elements in {@code array} are simple values - * @throws JSONException + * @throws JSONException JSON parsing error * @see #isSimpleValue(Object) */ public static boolean allSimpleValues(JSONArray array) throws JSONException { @@ -133,7 +144,7 @@ public static boolean isSimpleValue(Object o) { * * @param array the array to inspect * @return true if all the elements in the given array are JSONObjects - * @throws JSONException + * @throws JSONException JSON parsing error */ public static boolean allJSONObjects(JSONArray array) throws JSONException { for (int i = 0; i < array.length(); ++i) { @@ -149,7 +160,7 @@ public static boolean allJSONObjects(JSONArray array) throws JSONException { * * @param array the array to inspect * @return true if all the elements in the given array are JSONArrays - * @throws JSONException + * @throws JSONException JSON parsing error */ public static boolean allJSONArrays(JSONArray array) throws JSONException { for (int i = 0; i < array.length(); ++i) { From 2dfd140606464b204fed5aedf3397b36bd648f90 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 17:35:12 -0400 Subject: [PATCH 35/84] Removed single-author copyright at top. Leaving generic. --- src/main/java/org/json/JSONString.java | 2 -- src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java | 2 -- .../org/skyscreamer/jsonassert/LocationAwareValueMatcher.java | 2 -- .../skyscreamer/jsonassert/RegularExpressionValueMatcher.java | 2 -- .../java/org/skyscreamer/jsonassert/ValueMatcherException.java | 2 -- .../skyscreamer/jsonassert/comparator/ArraySizeComparator.java | 2 -- .../org/skyscreamer/jsonassert/comparator/JSONComparator.java | 2 -- .../java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java | 2 -- src/test/java/org/skyscreamer/jsonassert/DependencyTest.java | 2 -- .../jsonassert/RegularExpressionValueMatcherTest.java | 2 -- .../jsonassert/comparator/ArraySizeComparatorTest.java | 2 -- .../skyscreamer/jsonassert/comparator/CustomComparatorTest.java | 2 -- .../skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java | 2 -- 13 files changed, 26 deletions(-) diff --git a/src/main/java/org/json/JSONString.java b/src/main/java/org/json/JSONString.java index b41c6766..7360ddd3 100644 --- a/src/main/java/org/json/JSONString.java +++ b/src/main/java/org/json/JSONString.java @@ -1,6 +1,4 @@ /* - * Copyright 2016 sasdjb. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java index ec572751..ea3ebaf8 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Duncan Mackinder. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java index df492744..32891b62 100644 --- a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Duncan Mackinder. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java index 9f1a1baf..2a9efa54 100644 --- a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Duncan Mackinder. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java b/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java index abd44e3c..19807722 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java +++ b/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Duncan Mackinder. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java index 059325b5..35a62981 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Duncan Mackinder. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java index 8a75e429..65ee88e5 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java @@ -1,6 +1,4 @@ /* - * Copyright 2013 Ivan Zaytsev. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java index cb0c0712..b7f29e1c 100644 --- a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Duncan Mackinder. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/test/java/org/skyscreamer/jsonassert/DependencyTest.java b/src/test/java/org/skyscreamer/jsonassert/DependencyTest.java index 37b6d44d..ad0519da 100644 --- a/src/test/java/org/skyscreamer/jsonassert/DependencyTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/DependencyTest.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Carter Page. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java index 9e644596..0e591da8 100644 --- a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Duncan Mackinder. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java index 4449ff43..c949e8b8 100644 --- a/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java @@ -1,6 +1,4 @@ /* - * Copyright 2012 Duncan Mackinder. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java index 5c304c99..651e6a87 100644 --- a/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java @@ -1,6 +1,4 @@ /* - * Copyright 2013 Ivan Zaytsev. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java index d7691732..65f03b1e 100644 --- a/src/test/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtilTest.java @@ -1,6 +1,4 @@ /* - * Copyright 2013 Carter Page. - * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at From e5b43a88c951fff811787913decaf00dafe8f242 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 17:37:08 -0400 Subject: [PATCH 36/84] Mention license headers in Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e48f61a..c8c57f03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ Version 1.5.0 - 3/19/2017 ------------------------- - JSONassert now supports user-supplied error messages (thanks yasin3061@!) - Some refactoring / code health cleanup (thanks picimako@!) + - License headers on individual files Version 1.4.0 - 10/30/2016 -------------------------- From 102daa75277661d8e9108f5629f4f66690890672 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 17:37:45 -0400 Subject: [PATCH 37/84] Mention javadocs in changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c8c57f03..0c9fef76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ Version 1.5.0 - 3/19/2017 - JSONassert now supports user-supplied error messages (thanks yasin3061@!) - Some refactoring / code health cleanup (thanks picimako@!) - License headers on individual files + - Java 8 friendly javadocs Version 1.4.0 - 10/30/2016 -------------------------- From 7d22b4825409e6ca81cee628d88fd3f02d178a0e Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 17:40:38 -0400 Subject: [PATCH 38/84] Fix compiler error due to param rename. --- .../java/org/skyscreamer/jsonassert/JSONCompareResult.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java index a9400af7..28406fbe 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java @@ -227,15 +227,15 @@ private String formatMissing(String field, Object expected) { * @return result of comparison */ public JSONCompareResult unexpected(String field, Object actual) { - _fieldUnexpected.add(new FieldComparisonFailure(field, null, value)); - fail(formatUnexpected(field, value)); + _fieldUnexpected.add(new FieldComparisonFailure(field, null, actual)); + fail(formatUnexpected(field, actual)); return this; } private String formatUnexpected(String field, Object actual) { return field + "\nUnexpected: " - + describe(value) + + describe(actual) + "\n"; } From f75cf9b8ab774e1291709f2d8ebd58c2e023630e Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 17:42:06 -0400 Subject: [PATCH 39/84] [maven-release-plugin] prepare release jsonassert-1.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eb99a8df..e194839a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.4.1-SNAPSHOT + 1.5.0 jar JSONassert From e31d4d97c1888a8cf4901e14b108effb9900f78b Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 17:42:15 -0400 Subject: [PATCH 40/84] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e194839a..70a0456a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.0 + 1.5.1-SNAPSHOT jar JSONassert From 21cfa8b04de20f90325e34b4c4d78b9c9fdc09d6 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 17:53:00 -0400 Subject: [PATCH 41/84] Reverting to pre-release --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 70a0456a..eb99a8df 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.1-SNAPSHOT + 1.4.1-SNAPSHOT jar JSONassert From 9613bbe9580d6088a4c572572b6590c55b76da71 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 18:18:18 -0400 Subject: [PATCH 42/84] [maven-release-plugin] prepare release jsonassert-1.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eb99a8df..e194839a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.4.1-SNAPSHOT + 1.5.0 jar JSONassert From 339479a89dda6a9cd655aa57ed65786616db82fe Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 18:19:29 -0400 Subject: [PATCH 43/84] Revert "[maven-release-plugin] prepare release jsonassert-1.5.0" This reverts commit f75cf9b8ab774e1291709f2d8ebd58c2e023630e. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e194839a..eb99a8df 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.0 + 1.4.1-SNAPSHOT jar JSONassert From 055e9f80bbe8a4c3ede2fbf9acd2da20e9a9e2ce Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 18:22:22 -0400 Subject: [PATCH 44/84] [maven-release-plugin] prepare release jsonassert-1.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eb99a8df..e194839a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.4.1-SNAPSHOT + 1.5.0 jar JSONassert From 2ddd936238a69beb0ce0d3e88cf3eea9bba2e4d6 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 18:22:30 -0400 Subject: [PATCH 45/84] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e194839a..70a0456a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.0 + 1.5.1-SNAPSHOT jar JSONassert From 21d62b61299a02bfe871436699fc526e14f6b8f7 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 18:27:45 -0400 Subject: [PATCH 46/84] Revert "[maven-release-plugin] prepare release jsonassert-1.5.0" This reverts commit f75cf9b8ab774e1291709f2d8ebd58c2e023630e. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 70a0456a..eb99a8df 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.1-SNAPSHOT + 1.4.1-SNAPSHOT jar JSONassert From a47fe8397cb1b7ebb4cd60600c1d48b19c53b78c Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 18:29:34 -0400 Subject: [PATCH 47/84] [maven-release-plugin] prepare release jsonassert-1.5.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eb99a8df..e194839a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.4.1-SNAPSHOT + 1.5.0 jar JSONassert From 830efcf546d07f955d8a213cc5c8a1db34d78f04 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 19 Mar 2017 18:29:42 -0400 Subject: [PATCH 48/84] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e194839a..70a0456a 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.0 + 1.5.1-SNAPSHOT jar JSONassert From b83b7adaab007575f4d84aa2519018e3ec971be5 Mon Sep 17 00:00:00 2001 From: jakob Date: Fri, 6 Oct 2017 11:54:40 +0200 Subject: [PATCH 49/84] Added convenience methods for JSONObject comparison using a custom JSONComparator --- .../skyscreamer/jsonassert/JSONAssert.java | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java index d2a31cd1..efebf43c 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java @@ -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}. From d46714c9d2de6ff4de027f0d2f4ce046cc96a120 Mon Sep 17 00:00:00 2001 From: "anantharaman.g" Date: Fri, 26 Oct 2018 17:22:39 +0530 Subject: [PATCH 50/84] Fixes for issue #105 --- .../comparator/AbstractComparator.java | 15 ++++-- .../comparator/DefaultComparator.java | 6 +++ .../comparator/JSONCompareUtil.java | 16 +++++- .../jsonassert/JSONArrayWithNullTest.java | 49 +++++++++++++++++++ 4 files changed, 80 insertions(+), 6 deletions(-) create mode 100644 src/test/java/org/skyscreamer/jsonassert/JSONArrayWithNullTest.java diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java index 41b0ea0f..4f68e2d1 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java @@ -124,8 +124,8 @@ protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JS protected void compareJSONArrayWithStrictOrder(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException { for (int i = 0; i < expected.length(); ++i) { - Object expectedValue = expected.get(i); - Object actualValue = actual.get(i); + Object expectedValue = JSONCompareUtil.getObjectOrNull(expected, i); + Object actualValue = JSONCompareUtil.getObjectOrNull(actual, i); compareValues(key + "[" + i + "]", expectedValue, actualValue, result); } } @@ -138,10 +138,17 @@ protected void recursivelyCompareJSONArray(String key, JSONArray expected, JSONA JSONCompareResult result) throws JSONException { Set matched = new HashSet(); for (int i = 0; i < expected.length(); ++i) { - Object expectedElement = expected.get(i); + Object expectedElement = JSONCompareUtil.getObjectOrNull(expected, i); boolean matchFound = false; for (int j = 0; j < actual.length(); ++j) { - Object actualElement = actual.get(j); + Object actualElement = JSONCompareUtil.getObjectOrNull(actual, j); + if (expectedElement == actualElement) { + matchFound = true; + break; + } + if ((expectedElement == null && actualElement != null) || (expectedElement != null && actualElement == null)) { + continue; + } if (matched.contains(j) || !actualElement.getClass().equals(expectedElement.getClass())) { continue; } diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java index d7a210dc..bc71eae4 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java @@ -50,6 +50,12 @@ public void compareJSON(String prefix, JSONObject expected, JSONObject actual, J @Override public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException { + if (expectedValue == actualValue) { + return; + } + if ((expectedValue == null && actualValue != null) || (expectedValue != null && actualValue == null)) { + result.fail(prefix, expectedValue, actualValue); + } if (areNumbers(expectedValue, actualValue)) { if (areNotSameDoubles(expectedValue, actualValue)) { result.fail(prefix, expectedValue, actualValue); diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java index 617df012..a6bcc4ce 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java @@ -121,11 +121,23 @@ public static boolean isUsableAsUniqueKey(String candidate, JSONArray array) thr public static List jsonArrayToList(JSONArray expected) throws JSONException { List jsonObjects = new ArrayList(expected.length()); for (int i = 0; i < expected.length(); ++i) { - jsonObjects.add(expected.get(i)); + jsonObjects.add(getObjectOrNull(expected, i)); } return jsonObjects; } + /** + * Returns the value present in the given index position. If null value is present, it will return null + * + * @param jsonArray the JSON array to get value from + * @param index index of object to retrieve + * @return value at the given index position + * @throws JSONException JSON parsing error + */ + public static Object getObjectOrNull(JSONArray jsonArray, int index) throws JSONException { + return jsonArray.isNull(index) ? null : jsonArray.get(index); + } + /** * Returns whether all of the elements in the given array are simple values. * @@ -136,7 +148,7 @@ public static List jsonArrayToList(JSONArray expected) throws JSONExcept */ public static boolean allSimpleValues(JSONArray array) throws JSONException { for (int i = 0; i < array.length(); ++i) { - if (!isSimpleValue(array.get(i))) { + if (!array.isNull(i) && !isSimpleValue(array.get(i))) { return false; } } diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONArrayWithNullTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONArrayWithNullTest.java new file mode 100644 index 00000000..c5a5da5f --- /dev/null +++ b/src/test/java/org/skyscreamer/jsonassert/JSONArrayWithNullTest.java @@ -0,0 +1,49 @@ +package org.skyscreamer.jsonassert; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; + +public class JSONArrayWithNullTest { + @Test + public void testJSONArrayWithNullValue() throws JSONException { + JSONArray jsonArray1 = getJSONArray1(); + JSONArray jsonArray2 = getJSONArray2(); + + JSONAssert.assertEquals(jsonArray1, jsonArray2, true); + JSONAssert.assertEquals(jsonArray1, jsonArray2, false); + } + + @Test + public void testJSONArrayWithNullValueAndJsonObject() throws JSONException { + JSONArray jsonArray1 = getJSONArray1(); + JSONObject jsonObject1 = new JSONObject(); + jsonObject1.put("hey", "value"); + + JSONArray jsonArray2 = getJSONArray2(); + JSONObject jsonObject2 = new JSONObject(); + jsonObject2.put("hey", "value"); + + JSONAssert.assertEquals(jsonArray1, jsonArray2, true); + JSONAssert.assertEquals(jsonArray1, jsonArray2, false); + } + + private JSONArray getJSONArray1() { + JSONArray jsonArray1 = new JSONArray(); + jsonArray1.put(1); + jsonArray1.put(null); + jsonArray1.put(3); + jsonArray1.put(2); + return jsonArray1; + } + + private JSONArray getJSONArray2() { + JSONArray jsonArray1 = new JSONArray(); + jsonArray1.put(1); + jsonArray1.put(null); + jsonArray1.put(3); + jsonArray1.put(2); + return jsonArray1; + } +} From 437e1370ad2ea96c8b9a922da99d92c7821baf2e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 12 Oct 2020 20:44:21 +0000 Subject: [PATCH 51/84] Bump junit from 4.10 to 4.13.1 Bumps [junit](https://github.com/junit-team/junit4) from 4.10 to 4.13.1. - [Release notes](https://github.com/junit-team/junit4/releases) - [Changelog](https://github.com/junit-team/junit4/blob/main/doc/ReleaseNotes4.10.md) - [Commits](https://github.com/junit-team/junit4/compare/r4.10...r4.13.1) Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 70a0456a..6c369586 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ junit junit - 4.10 + 4.13.1 test From 7817189a46d9fd699ca018f082f82913d7b59339 Mon Sep 17 00:00:00 2001 From: Martin van Wingerden Date: Tue, 27 Oct 2020 09:22:43 +0100 Subject: [PATCH 52/84] Update README.md to align test-scope --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c28ba6de..bdbdd87f 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert 1.5.0 - test + test Write tests like this: From c7f5479c0fdb367db2454bc20278f261dec908a0 Mon Sep 17 00:00:00 2001 From: Igor Manushin Date: Tue, 25 Jan 2022 19:14:12 +0000 Subject: [PATCH 53/84] Add gitignore file --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..ec376bb8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +target \ No newline at end of file From 1e7ee6532c648d8eb9e49e39e8c8eeb710bb3b7b Mon Sep 17 00:00:00 2001 From: Igor Manushin Date: Tue, 25 Jan 2022 19:21:11 +0000 Subject: [PATCH 54/84] Bump all dependencies --- pom.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 6c369586..5500241f 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ junit junit - 4.13.1 + 4.13.2 test @@ -76,13 +76,13 @@ org.apache.maven.plugins maven-site-plugin - 3.3 + 3.10.0 org.codehaus.mojo cobertura-maven-plugin - 2.5.1 + 2.7 @@ -92,12 +92,12 @@ org.apache.maven.scm maven-scm-provider-gitexe - 1.3 + 1.12.2 org.apache.maven.scm maven-scm-manager-plexus - 1.3 + 1.12.2 org.kathrynhuxtable.maven.wagon @@ -128,7 +128,7 @@ org.apache.maven.plugins maven-gpg-plugin - 1.1 + 3.0.1 sign-artifacts From 676de0b66d1d077cc58977360a35e421a2e17541 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Mon, 4 Jul 2022 10:06:10 -0400 Subject: [PATCH 55/84] Updating documention to version 1.5.1. --- README.md | 2 +- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bdbdd87f..e7504f42 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert - 1.5.0 + 1.5.1 test diff --git a/src/site/resources/index.html b/src/site/resources/index.html index 98d14384..18028055 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

    Introduction

  • JUnit
  • -


    The current version of JSONassert is 1.5.0

    +


    The current version of JSONassert is 1.5.1

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index 67f7e637..f3cb03d7 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>1.5.0</version>
    +   <version>1.5.1</version>
    </dependency>
    From 2b41ebb21c43ea439ea1d2857f9889ddfe456d21 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Mon, 4 Jul 2022 10:19:47 -0400 Subject: [PATCH 56/84] Updated CHANGELOG.md with new changes. --- CHANGELOG.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c9fef76..b64059a9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,14 @@ Changelog ========= +Version 1.5.1 - 7/4/2022 +------------------------ +Going to try to catch up on some ancient PRs, mainly around security and cleanup. Starting with accepted PRs that +didn't get released yet. To be followed hopefully shortly with another release. + - Added convenience methods for JSONObject comparison using a custom JSONComparator (thanks jakob-o@!) + - Fix issue #105: Issue when comparing JSONArray if any value is null (thanks suraj1291993@!) + - Fixes security vulnerability associated with older version of junit + Version 1.5.0 - 3/19/2017 ------------------------- - JSONassert now supports user-supplied error messages (thanks yasin3061@!) @@ -16,12 +24,12 @@ Version 1.4.0 - 10/30/2016 Version 1.3.0 - 12/16/2015 -------------------------- - - Fix & improve ArrayValueMatcher JavaDoc (thanks dmackinder!) + - Fix & improve ArrayValueMatcher JavaDoc (thanks dmackinder@!) Fix final JavaDoc example and add new example showing how to verify every array element using a custom comparator - - Fix URL in pom.xml (aukevanleeuwen) - - Update JSONCompareResult.java adding 2 new lists for missing and unexpected fileds (thanks riccorazza!) - - Includes missing imports in test class (thanks javierseixas!) + - Fix URL in pom.xml (aukevanleeuwen@) + - Update JSONCompareResult.java adding 2 new lists for missing and unexpected fileds (thanks riccorazza@!) + - Includes missing imports in test class (thanks javierseixas@!) Version 1.2.3 - 2/5/2014 ------------------------ @@ -38,7 +46,8 @@ Version 1.2.2 - 12/31/2013 Version 1.2.1 - 10/24/2013 -------------------------- - Remove commons-collection dependency - - Updated Customization class to allow path-matching, and matching of expected and actual values with user-provided EqualityComparator. + - Updated Customization class to allow path-matching, and matching of expected and actual values with user-provided + EqualityComparator. - Added AssertNotEquals Version 1.2.0 - 3/17/2013 From a0f19f4c8ea428ecc7d49e8c5ac8b000cf6ce014 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Mon, 4 Jul 2022 11:21:29 -0400 Subject: [PATCH 57/84] [maven-release-plugin] prepare release jsonassert-1.5.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c369586..c6d53ffd 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.1-SNAPSHOT + 1.5.1 jar JSONassert From becf5b67b44b881cfe06961c491d32269d6af10e Mon Sep 17 00:00:00 2001 From: Carter Page Date: Mon, 4 Jul 2022 11:21:30 -0400 Subject: [PATCH 58/84] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c6d53ffd..5f5d816c 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.1 + 1.5.2-SNAPSHOT jar JSONassert From 1dfc63175f651b3cb06c1aff8b6429dd9c0aa4ef Mon Sep 17 00:00:00 2001 From: carterpage Date: Mon, 4 Jul 2022 15:17:22 -0400 Subject: [PATCH 59/84] Revert "[maven-release-plugin] prepare for next development iteration" This reverts commit becf5b67b44b881cfe06961c491d32269d6af10e. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5f5d816c..c6d53ffd 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.2-SNAPSHOT + 1.5.1 jar JSONassert From 6291bc874ecbbe71bc5be82b2f077d7ae1d96a99 Mon Sep 17 00:00:00 2001 From: carterpage Date: Mon, 4 Jul 2022 15:17:47 -0400 Subject: [PATCH 60/84] Revert "[maven-release-plugin] prepare release jsonassert-1.5.1" This reverts commit a0f19f4c8ea428ecc7d49e8c5ac8b000cf6ce014. --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c6d53ffd..6c369586 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.1 + 1.5.1-SNAPSHOT jar JSONassert From be6313959dbc218dfd4ad7cbce818840f6133dea Mon Sep 17 00:00:00 2001 From: carterpage Date: Mon, 4 Jul 2022 15:27:33 -0400 Subject: [PATCH 61/84] [maven-release-plugin] prepare release jsonassert-1.5.1 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c369586..c6d53ffd 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.1-SNAPSHOT + 1.5.1 jar JSONassert From d76e85e2436db04ee677dfade3a49b601a39f1f7 Mon Sep 17 00:00:00 2001 From: carterpage Date: Mon, 4 Jul 2022 15:27:36 -0400 Subject: [PATCH 62/84] [maven-release-plugin] prepare for next development iteration --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c6d53ffd..5f5d816c 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ org.skyscreamer jsonassert - 1.5.1 + 1.5.2-SNAPSHOT jar JSONassert From 7414e901af11c559bc553e5bb8e12b99a57d1c1c Mon Sep 17 00:00:00 2001 From: RushikeshNaiknaware <52272094+RushikeshNaiknaware@users.noreply.github.com> Date: Mon, 11 Jul 2022 18:50:49 +0530 Subject: [PATCH 63/84] Updated ReadMe for syntax errors of strike of code (#147) Syntax error corrections on strike of code. Correcting the assert methods name as Assert.assertTrue() Making assertion pass by swapping the value of friend1Obj with friend2Obj. --- README.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index e7504f42..ca17fb49 100644 --- a/README.md +++ b/README.md @@ -29,22 +29,23 @@ Assert.assertTrue(data.has("friends")); Object friendsObject = data.get("friends"); Assert.assertTrue(friendsObject instanceof JSONArray); JSONArray friends = (JSONArray) friendsObject; -Assert.assertEquals(2, data.length()); -JSONObject friend1Obj = friends.getJSONObject(data.get(0)); -Assert.true(friend1Obj.has("id")); -Assert.true(friend1Obj.has("name")); -JSONObject friend2Obj = friends.getJSONObject(data.get(1)); -Assert.true(friend2Obj.has("id")); -Assert.true(friend2Obj.has("name")); +Assert.assertEquals(2, friends.length()); +JSONObject friend1Obj = friends.getJSONObject(0); +Assert.assertTrue(friend1Obj.has("id")); +Assert.assertTrue(friend1Obj.has("name")); +JSONObject friend2Obj = friends.getJSONObject(1); +Assert.assertTrue(friend2Obj.has("id")); +Assert.assertTrue(friend2Obj.has("name")); + if ("Carter Page".equals(friend1Obj.getString("name"))) { - Assert.assertEquals(123, friend1Obj.getInt("id")); + Assert.assertEquals(456, friend1Obj.getInt("id")); Assert.assertEquals("Corby Page", friend2Obj.getString("name")); - Assert.assertEquals(456, friend2Obj.getInt("id")); + Assert.assertEquals(123, friend2Obj.getInt("id")); } else if ("Corby Page".equals(friend1Obj.getString("name"))) { - Assert.assertEquals(456, friend1Obj.getInt("id")); + Assert.assertEquals(123, friend1Obj.getInt("id")); Assert.assertEquals("Carter Page", friend2Obj.getString("name")); - Assert.assertEquals(123, friend2Obj.getInt("id")); + Assert.assertEquals(456, friend2Obj.getInt("id")); } else { Assert.fail("Expected either Carter or Corby, Got: " + friend1Obj.getString("name")); From 313c61bb9c3494dfe9253bfe6395fe5fc99b5af2 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Mon, 17 Jun 2024 08:29:54 -0400 Subject: [PATCH 64/84] Update documentation and CHANGELOG to 1.5.2. (#186) Co-authored-by: Carter Page --- CHANGELOG.md | 7 +++++++ README.md | 2 +- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b64059a9..0048f1be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========= +Version 1.5.2 - 7/14/2024 +------------------------- + - Fix CVE-2020-15250 JUnit vulnerability (https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-15250). Bump + dependencies. + - Add gitIgnore file + - README syntax error fix + Version 1.5.1 - 7/4/2022 ------------------------ Going to try to catch up on some ancient PRs, mainly around security and cleanup. Starting with accepted PRs that diff --git a/README.md b/README.md index ca17fb49..2a0c4d0f 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert - 1.5.1 + 1.5.2 test diff --git a/src/site/resources/index.html b/src/site/resources/index.html index 18028055..b2222f1d 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

    Introduction

  • JUnit
  • -


    The current version of JSONassert is 1.5.1

    +


    The current version of JSONassert is 1.5.2

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index f3cb03d7..c80de6fb 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>1.5.1</version>
    +   <version>1.5.2</version>
    </dependency>
    From 8e2ba629c25def78ff7fde58b25e89de10677cc5 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Mon, 17 Jun 2024 08:40:11 -0400 Subject: [PATCH 65/84] Bump pom.xml target/source from 6 to 8. (#187) * Updated source/target from 6 to 8. --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 19b055c2..80d19f69 100644 --- a/pom.xml +++ b/pom.xml @@ -69,8 +69,8 @@ maven-compiler-plugin 2.3.1 - 1.6 - 1.6 + 1.8 + 1.8
    From eebcfe8e50b8681f8a1422106b72e25b48d7be12 Mon Sep 17 00:00:00 2001 From: Corby Page Date: Sat, 22 Jun 2024 14:00:14 -0500 Subject: [PATCH 66/84] Update to Java 21 (#188) * Setting maven.compiler.release to 21 * Updating nexus staging maven plugin * Updated source/Javadoc plugin --- pom.xml | 84 ++++++++++++++----- .../jsonassert/ArrayValueMatcher.java | 2 +- .../jsonassert/JSONCompareMode.java | 5 +- .../jsonassert/LocationAwareValueMatcher.java | 2 +- .../RegularExpressionValueMatcher.java | 2 +- .../comparator/AbstractComparator.java | 22 +++++ 6 files changed, 92 insertions(+), 25 deletions(-) diff --git a/pom.xml b/pom.xml index 80d19f69..68d0cdac 100644 --- a/pom.xml +++ b/pom.xml @@ -2,21 +2,19 @@ 4.0.0 - - org.sonatype.oss - oss-parent - 7 - - org.skyscreamer jsonassert - 1.5.2-SNAPSHOT + 1.5.2 jar JSONassert A library to develop RESTful but flexible APIs https://github.com/skyscreamer/JSONassert + + 21 + + The Apache Software License, Version 2.0 @@ -60,6 +58,12 @@ 4.13.2 test + + org.hamcrest + hamcrest + 2.2 + test + @@ -67,25 +71,59 @@ org.apache.maven.plugins maven-compiler-plugin - 2.3.1 - - 1.8 - 1.8 - + 3.11.0 org.apache.maven.plugins maven-site-plugin - 3.10.0 + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + ${java.home}/bin/javadoc + 8 + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true - - - org.codehaus.mojo - cobertura-maven-plugin - 2.7 - - + ossrh + https://oss.sonatype.org/ + true + + + com.thoughtworks.xstream + xstream + 1.4.15 + + @@ -112,6 +150,10 @@ github-project-site gitsite:git@github.com/skyscreamer/JSONassert.git + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + @@ -128,7 +170,7 @@ org.apache.maven.plugins maven-gpg-plugin - 3.0.1 + 1.5 sign-artifacts diff --git a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java index ea3ebaf8..2d4dd8ec 100644 --- a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java @@ -133,7 +133,7 @@ *

    To simplify complexity of expected JSON string, the value "{a:[[9]]}" may be replaced by "{a:[9]}" or "{a:9}"

    * * @author Duncan Mackinder - * + * @param Array Type */ public class ArrayValueMatcher implements LocationAwareValueMatcher { private final JSONComparator comparator; diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java index d676be45..8185b065 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareMode.java @@ -18,7 +18,10 @@ *

    These different modes define different behavior for the comparison of JSON for testing. * Each mode encapsulates two underlying behaviors: extensibility and strict ordering.

    * - *
     ExtensibleStrict Ordering
    STRICTnoyes
    LENIENTyesno
    + *
    + * * * * diff --git a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java index 32891b62..cc2b7449 100644 --- a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java @@ -21,7 +21,7 @@ * A ValueMatcher extension that provides location in form of prefix to the equals method. * * @author Duncan Mackinder - * + * @param Generic Type */ public interface LocationAwareValueMatcher extends ValueMatcher { diff --git a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java index 2a9efa54..19a4ef1d 100644 --- a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java +++ b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java @@ -28,7 +28,7 @@ * specify regular expression pattern that actual value must match. * * @author Duncan Mackinder - * + * @param Generic Type */ public class RegularExpressionValueMatcher implements ValueMatcher { diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java index 4f68e2d1..45b98a96 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java @@ -26,9 +26,17 @@ /** * This class provides a skeletal implementation of the {@link JSONComparator} * interface, to minimize the effort required to implement this interface. + * + * */ public abstract class AbstractComparator implements JSONComparator { + /** + * Default constructor + */ + public AbstractComparator() { + } + /** * Compares JSONObject provided to the expected JSONObject, and returns the results of the comparison. * @@ -57,6 +65,12 @@ public final JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) return result; } + /** + * @param prefix + * @param expected + * @param actual + * @param result + */ protected void checkJsonObjectKeysActualInExpected(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) { Set actualKeys = getKeys(actual); for (String key : actualKeys) { @@ -66,6 +80,14 @@ protected void checkJsonObjectKeysActualInExpected(String prefix, JSONObject exp } } + /** + * + * @param prefix + * @param expected + * @param actual + * @param result + * @throws JSONException + */ protected void checkJsonObjectKeysExpectedInActual(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) throws JSONException { Set expectedKeys = getKeys(expected); for (String key : expectedKeys) { From 3112d8e0f0c116ff3c5c739c8c4d3dbc5b9f5331 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 28 Jun 2024 07:25:30 -0400 Subject: [PATCH 67/84] Revert from Java 21 to 8 (#192) * Reverting from version 21 to version 8. * Update description and developers in pom.xml. --- pom.xml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 68d0cdac..6bf265a0 100644 --- a/pom.xml +++ b/pom.xml @@ -8,11 +8,11 @@ jar JSONassert - A library to develop RESTful but flexible APIs + Write JSON unit tests in less code. Great for testing REST interfaces. https://github.com/skyscreamer/JSONassert - 21 + 8 @@ -33,16 +33,15 @@ Carter Page carter@skyscreamer.org + + hertzsprung + James Shaw + cepage Corby Page corby@skyscreamer.org - - sduskis - Solomon Duskis - solomon@skyscreamer.org - From f7ebd4b575b44009382de6e439920391178345cb Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 28 Jun 2024 07:31:13 -0400 Subject: [PATCH 68/84] Prepare for release of 1.5.3 --- CHANGELOG.md | 7 ++++++- README.md | 2 +- pom.xml | 2 +- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0048f1be..c1ce3302 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,17 @@ Changelog ========= -Version 1.5.2 - 7/14/2024 +Version 1.5.3 - 6/28/2024 +------------------------- + - Revert Java release version from 21 to 8 due to breaking older compilers. + +Version 1.5.2 - 6/14/2024 ------------------------- - Fix CVE-2020-15250 JUnit vulnerability (https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2020-15250). Bump dependencies. - Add gitIgnore file - README syntax error fix + - Accidentally upgraded release to Java version 21 Version 1.5.1 - 7/4/2022 ------------------------ diff --git a/README.md b/README.md index 2a0c4d0f..6b046814 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert - 1.5.2 + 1.5.3 test diff --git a/pom.xml b/pom.xml index 6bf265a0..6760f731 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.skyscreamer jsonassert - 1.5.2 + 1.5.3 jar JSONassert diff --git a/src/site/resources/index.html b/src/site/resources/index.html index b2222f1d..2bca2d18 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

    Introduction

  • JUnit
  • -


    The current version of JSONassert is 1.5.2

    +


    The current version of JSONassert is 1.5.3

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index c80de6fb..00b36f86 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>1.5.2</version>
    +   <version>1.5.3</version>
    </dependency>
    From 721abb082ee093bc148d9786bf2c131a763522d7 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 28 Jun 2024 09:01:38 -0400 Subject: [PATCH 69/84] Updated pom.xml file for new release process. --- pom.xml | 72 ++++++++++++++++++++++++++------------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/pom.xml b/pom.xml index 6760f731..04d7141e 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.skyscreamer jsonassert - 1.5.3 + 1.5.3-SNAPSHOT jar JSONassert @@ -76,36 +76,6 @@ org.apache.maven.plugins maven-site-plugin - - org.apache.maven.plugins - maven-source-plugin - 2.2.1 - - - attach-sources - - jar-no-fork - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - 2.9.1 - - - attach-javadocs - - jar - - - - - ${java.home}/bin/javadoc - 8 - - org.sonatype.plugins nexus-staging-maven-plugin @@ -114,7 +84,7 @@ ossrh https://oss.sonatype.org/ - true + false @@ -157,15 +127,39 @@ - release-sign-artifacts - - - performRelease - true - - + deploy + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + ${java.home}/bin/javadoc + ${maven.compiler.release} + + org.apache.maven.plugins maven-gpg-plugin From b1750da5b45924f65039a1b7c62d8123437fc64a Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 28 Jun 2024 09:10:57 -0400 Subject: [PATCH 70/84] Removed snapshot for release 1.5.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 04d7141e..25c7f7fa 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.skyscreamer jsonassert - 1.5.3-SNAPSHOT + 1.5.3 jar JSONassert From 8b9be3ccabda038b3d6d0ba7496a2a7d76b43c6f Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 19 Jul 2024 15:56:29 -0400 Subject: [PATCH 71/84] Finally moving to official org.json implementation! (#194) * Replaced org.json with stleary/JSON-java library. * Checkpoint. Beginning to removing JSONException imports since it is now a RuntimeException. * Completed removal of explicit throws JSONException since it is now a RuntimeException. * Updated README to account for new dependency and removal of old. * One last unnecessary JSONException reference. * Library change breaks some behavior and is a major shift. Incrementing major version. --- CHANGELOG.md | 4 + README.md | 9 +- pom.xml | 8 +- src/main/java/org/json/JSONString.java | 36 ---- .../skyscreamer/jsonassert/JSONAssert.java | 200 +++++------------- .../skyscreamer/jsonassert/JSONCompare.java | 25 +-- .../skyscreamer/jsonassert/JSONParser.java | 3 +- .../comparator/AbstractComparator.java | 18 +- .../comparator/ArraySizeComparator.java | 3 +- .../comparator/CustomComparator.java | 3 +- .../comparator/DefaultComparator.java | 10 +- .../jsonassert/comparator/JSONComparator.java | 16 +- .../comparator/JSONCompareUtil.java | 25 +-- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- .../jsonassert/ArrayValueMatcherTest.java | 61 +++--- .../jsonassert/JSONArrayWithNullTest.java | 9 +- .../jsonassert/JSONAssertTest.java | 135 ++++++------ .../jsonassert/JSONCompareTest.java | 41 ++-- .../jsonassert/JSONCustomComparatorTest.java | 11 +- .../RegularExpressionValueMatcherTest.java | 27 ++- .../comparator/ArraySizeComparatorTest.java | 39 ++-- .../comparator/CustomComparatorTest.java | 3 +- 23 files changed, 259 insertions(+), 431 deletions(-) delete mode 100644 src/main/java/org/json/JSONString.java diff --git a/CHANGELOG.md b/CHANGELOG.md index c1ce3302..0240ee0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ Changelog ========= +Version 2.0.0 - TBD +------------------- + - TODO - placeholder + Version 1.5.3 - 6/28/2024 ------------------------- - Revert Java release version from 21 to 8 due to breaking older compilers. diff --git a/README.md b/README.md index 6b046814..d6b5a932 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert - 1.5.3 + 2.0.0-SNAPSHOT test @@ -97,16 +97,15 @@ Who uses JSONassert? + [GroupDocs](http://groupdocs.com/) + [Shazam](http://www.shazam.com/) + [Thucydides](http://thucydides.net/) + + [and over a thousand more](https://mvnrepository.com/artifact/org.skyscreamer/jsonassert)... * * * org.json -------- -This implementation uses a clean-room implementation of the org.json -library implemented for the Android system, released under the Apache 2.0 license. See -[com.vaadin.external.google:android-json](http://search.maven.org/#artifactdetails%7Ccom.vaadin.external.google%7Candroid-json%7C0.0.20131108.vaadin1%7Cjar) -That jar does **not** include the org.json.JSONString interface, so a new implementation of that interface is added to this source. +As of v2, JSONAssert uses @stleary's [JSON-java](https://github.com/stleary/JSON-java) implementation of org.json, the +most commonly used reference implementation for JSON in Java. Resources --------- diff --git a/pom.xml b/pom.xml index 25c7f7fa..cc1299a1 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.skyscreamer jsonassert - 1.5.3 + 2.0.0-SNAPSHOT jar JSONassert @@ -47,9 +47,9 @@ - com.vaadin.external.google - android-json - 0.0.20131108.vaadin1 + org.json + json + 20240303 junit diff --git a/src/main/java/org/json/JSONString.java b/src/main/java/org/json/JSONString.java deleted file mode 100644 index 7360ddd3..00000000 --- a/src/main/java/org/json/JSONString.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. -*/ - -package org.json; - -/** - * The JSONString interface allows a toJSONString() method so that a class can change - * the behavior of JSONObject.toString(), JSONArray.toString(), and JSONWriter.value(Object). - * The toJSONString method will be used instead of the default behavior of using the - * Object's toString() method and quoting the result. - * - * @author sasdjb - * - */ -public interface JSONString { - - /** - * The toJSONString method allows a class to produce its own JSON - * serialization. - * - * @return String representation of JSON object - * */ - String toJSONString(); - -} diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java index efebf43c..5a2eec18 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java @@ -15,7 +15,6 @@ package org.skyscreamer.jsonassert; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.comparator.JSONComparator; @@ -59,10 +58,8 @@ private JSONAssert() {} * @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 { + public static void assertEquals(String expectedStr, JSONObject actual, boolean strict) { assertEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -74,10 +71,8 @@ public static void assertEquals(String expectedStr, JSONObject actual, boolean s * @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 message, String expectedStr, JSONObject actual, boolean strict) - throws JSONException { + public static void assertEquals(String message, String expectedStr, JSONObject actual, boolean strict) { assertEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -90,10 +85,8 @@ public static void assertEquals(String message, String expectedStr, JSONObject a * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String expectedStr, JSONObject actual, boolean strict) - throws JSONException { + public static void assertNotEquals(String expectedStr, JSONObject actual, boolean strict) { assertNotEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -107,10 +100,8 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, boolea * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String message, String expectedStr, JSONObject actual, boolean strict) - throws JSONException { + public static void assertNotEquals(String message, String expectedStr, JSONObject actual, boolean strict) { assertNotEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -121,10 +112,8 @@ public static void assertNotEquals(String message, String expectedStr, JSONObjec * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException JSON parsing error */ - public static void assertEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) - throws JSONException { + public static void assertEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) { assertEquals("", expectedStr, actual, compareMode); } @@ -136,10 +125,9 @@ public static void assertEquals(String expectedStr, JSONObject actual, JSONCompa * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException JSON parsing error */ public static void assertEquals(String message, String expectedStr, JSONObject actual, JSONCompareMode compareMode) - throws JSONException { + { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONObject) { assertEquals(message, (JSONObject)expected, actual, compareMode); @@ -158,10 +146,8 @@ public static void assertEquals(String message, String expectedStr, JSONObject a * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) - throws JSONException { + public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCompareMode compareMode) { assertNotEquals("", expectedStr, actual, compareMode); } @@ -175,10 +161,9 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCo * @param expectedStr Expected JSON string * @param actual JSONObject to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String message, String expectedStr, JSONObject actual, JSONCompareMode compareMode) - throws JSONException { + public static void assertNotEquals(String message, String expectedStr, JSONObject actual, + JSONCompareMode compareMode) { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONObject) { assertNotEquals(message, (JSONObject) expected, actual, compareMode); @@ -195,10 +180,8 @@ public static void assertNotEquals(String message, String expectedStr, JSONObjec * @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 { + public static void assertEquals(String expectedStr, JSONArray actual, boolean strict) { assertEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -210,10 +193,8 @@ public static void assertEquals(String expectedStr, JSONArray actual, boolean st * @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 message, String expectedStr, JSONArray actual, boolean strict) - throws JSONException { + public static void assertEquals(String message, String expectedStr, JSONArray actual, boolean strict) { assertEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -224,10 +205,8 @@ public static void assertEquals(String message, String expectedStr, JSONArray ac * @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 { + public static void assertNotEquals(String expectedStr, JSONArray actual, boolean strict) { assertNotEquals(expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -239,10 +218,8 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, boolean * @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 message, String expectedStr, JSONArray actual, boolean strict) - throws JSONException { + public static void assertNotEquals(String message, String expectedStr, JSONArray actual, boolean strict) { assertNotEquals(message, expectedStr, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -253,10 +230,8 @@ public static void assertNotEquals(String message, String expectedStr, JSONArray * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException JSON parsing error */ - public static void assertEquals(String expectedStr, JSONArray actual, JSONCompareMode compareMode) - throws JSONException { + public static void assertEquals(String expectedStr, JSONArray actual, JSONCompareMode compareMode) { assertEquals("", expectedStr, actual, compareMode); } @@ -268,10 +243,8 @@ public static void assertEquals(String expectedStr, JSONArray actual, JSONCompar * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException JSON parsing error */ - public static void assertEquals(String message, String expectedStr, JSONArray actual, JSONCompareMode compareMode) - throws JSONException { + public static void assertEquals(String message, String expectedStr, JSONArray actual, JSONCompareMode compareMode) { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONArray) { assertEquals(message, (JSONArray) expected, actual, compareMode); @@ -288,10 +261,8 @@ public static void assertEquals(String message, String expectedStr, JSONArray ac * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCompareMode compareMode) - throws JSONException { + public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCompareMode compareMode) { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONArray) { assertNotEquals((JSONArray) expected, actual, compareMode); @@ -309,10 +280,9 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCom * @param expectedStr Expected JSON string * @param actual JSONArray to compare * @param compareMode Specifies which comparison mode to use - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String message, String expectedStr, JSONArray actual, JSONCompareMode compareMode) - throws JSONException { + public static void assertNotEquals(String message, String expectedStr, JSONArray actual, + JSONCompareMode compareMode) { Object expected = JSONParser.parseJSON(expectedStr); if (expected instanceof JSONArray) { assertNotEquals(message, (JSONArray) expected, actual, compareMode); @@ -329,10 +299,8 @@ public static void assertNotEquals(String message, String expectedStr, JSONArray * @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 { + public static void assertEquals(String expectedStr, String actualStr, boolean strict) { assertEquals(expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -344,10 +312,8 @@ public static void assertEquals(String expectedStr, String actualStr, boolean st * @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 message, String expectedStr, String actualStr, boolean strict) - throws JSONException { + public static void assertEquals(String message, String expectedStr, String actualStr, boolean strict) { assertEquals(message, expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -358,10 +324,8 @@ public static void assertEquals(String message, String expectedStr, String actua * @param expectedStr Expected JSON string * @param actualStr String to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String expectedStr, String actualStr, boolean strict) - throws JSONException { + public static void assertNotEquals(String expectedStr, String actualStr, boolean strict) { assertNotEquals(expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -373,10 +337,8 @@ public static void assertNotEquals(String expectedStr, String actualStr, boolean * @param expectedStr Expected JSON string * @param actualStr String to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String message, String expectedStr, String actualStr, boolean strict) - throws JSONException { + public static void assertNotEquals(String message, String expectedStr, String actualStr, boolean strict) { assertNotEquals(message, expectedStr, actualStr, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -387,10 +349,8 @@ public static void assertNotEquals(String message, String expectedStr, String ac * @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 expectedStr, String actualStr, JSONCompareMode compareMode) - throws JSONException { + public static void assertEquals(String expectedStr, String actualStr, JSONCompareMode compareMode) { assertEquals("", expectedStr, actualStr, compareMode); } @@ -402,10 +362,8 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar * @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 { + public static void assertEquals(String message, String expectedStr, String actualStr, JSONCompareMode compareMode) { if (expectedStr==actualStr) return; if (expectedStr==null){ throw new AssertionError("Expected string is null."); @@ -425,10 +383,8 @@ public static void assertEquals(String message, String expectedStr, String actua * @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 { + public static void assertNotEquals(String expectedStr, String actualStr, JSONCompareMode compareMode) { assertNotEquals("", expectedStr, actualStr, compareMode); } @@ -440,10 +396,9 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom * @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 message, String expectedStr, String actualStr, JSONCompareMode compareMode) - throws JSONException { + public static void assertNotEquals(String message, String expectedStr, String actualStr, + JSONCompareMode compareMode) { JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, compareMode); if (result.passed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); @@ -457,10 +412,8 @@ public static void assertNotEquals(String message, String expectedStr, String ac * @param expectedStr Expected JSON string * @param actualStr String to compare * @param comparator Comparator - * @throws JSONException JSON parsing error */ - public static void assertEquals(String expectedStr, String actualStr, JSONComparator comparator) - throws JSONException { + public static void assertEquals(String expectedStr, String actualStr, JSONComparator comparator) { assertEquals("", expectedStr, actualStr, comparator); } @@ -473,10 +426,8 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar * @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 { + public static void assertEquals(String message, String expectedStr, String actualStr, JSONComparator comparator) { JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, comparator); if (result.failed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); @@ -490,10 +441,8 @@ public static void assertEquals(String message, String expectedStr, String actua * @param expectedStr Expected JSON string * @param actualStr String to compare * @param comparator Comparator - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(String expectedStr, String actualStr, JSONComparator comparator) - throws JSONException { + public static void assertNotEquals(String expectedStr, String actualStr, JSONComparator comparator) { assertNotEquals("", expectedStr, actualStr, comparator); } @@ -505,10 +454,9 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom * @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 { + public static void assertNotEquals(String message, String expectedStr, String actualStr, + JSONComparator comparator) { JSONCompareResult result = JSONCompare.compareJSON(expectedStr, actualStr, comparator); if (result.passed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); @@ -522,10 +470,8 @@ public static void assertNotEquals(String message, String expectedStr, String ac * @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 { + public static void assertEquals(JSONObject expected, JSONObject actual, JSONComparator comparator) { assertEquals("", expected, actual, comparator); } @@ -537,10 +483,8 @@ public static void assertEquals(JSONObject expected, JSONObject actual, JSONComp * @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 { + public static void assertEquals(String message, JSONObject expected, JSONObject actual, JSONComparator comparator) { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, comparator); if (result.failed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); @@ -554,10 +498,8 @@ public static void assertEquals(String message, JSONObject expected, JSONObject * @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 { + public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONComparator comparator) { assertNotEquals("", expected, actual, comparator); } @@ -569,10 +511,9 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONC * @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 { + public static void assertNotEquals(String message, JSONObject expected, JSONObject actual, + JSONComparator comparator) { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, comparator); if (result.passed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); @@ -586,10 +527,8 @@ public static void assertNotEquals(String message, JSONObject expected, JSONObje * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertEquals(JSONObject expected, JSONObject actual, boolean strict) - throws JSONException { + public static void assertEquals(JSONObject expected, JSONObject actual, boolean strict) { assertEquals(expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -601,10 +540,8 @@ public static void assertEquals(JSONObject expected, JSONObject actual, boolean * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertEquals(String message, JSONObject expected, JSONObject actual, boolean strict) - throws JSONException { + public static void assertEquals(String message, JSONObject expected, JSONObject actual, boolean strict) { assertEquals(message, expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -615,10 +552,8 @@ public static void assertEquals(String message, JSONObject expected, JSONObject * @param expected Expected JSONObject * @param actual JSONObject to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(JSONObject expected, JSONObject actual, boolean strict) - throws JSONException { + public static void assertNotEquals(JSONObject expected, JSONObject actual, boolean strict) { assertNotEquals(expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -630,10 +565,8 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, boole * @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 { + public static void assertNotEquals(String message, JSONObject expected, JSONObject actual, boolean strict) { assertNotEquals(message, expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -644,10 +577,8 @@ public static void assertNotEquals(String message, JSONObject expected, JSONObje * @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 { + public static void assertEquals(JSONObject expected, JSONObject actual, JSONCompareMode compareMode) { assertEquals("", expected, actual, compareMode); } @@ -659,10 +590,9 @@ public static void assertEquals(JSONObject expected, JSONObject actual, JSONComp * @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 { + public static void assertEquals(String message, JSONObject expected, JSONObject actual, + JSONCompareMode compareMode) { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); if (result.failed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); @@ -676,10 +606,8 @@ public static void assertEquals(String message, JSONObject expected, JSONObject * @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 { + public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONCompareMode compareMode) { assertNotEquals("", expected, actual, compareMode); } @@ -691,10 +619,9 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONC * @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 { + public static void assertNotEquals(String message, JSONObject expected, JSONObject actual, + JSONCompareMode compareMode) { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); if (result.passed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); @@ -708,10 +635,8 @@ public static void assertNotEquals(String message, JSONObject expected, JSONObje * @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 { + public static void assertEquals(JSONArray expected, JSONArray actual, boolean strict) { assertEquals("", expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -723,10 +648,8 @@ public static void assertEquals(JSONArray expected, JSONArray actual, boolean st * @param expected Expected JSONArray * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertEquals(String message, JSONArray expected, JSONArray actual, boolean strict) - throws JSONException { + public static void assertEquals(String message, JSONArray expected, JSONArray actual, boolean strict) { assertEquals(message, expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -737,10 +660,8 @@ public static void assertEquals(String message, JSONArray expected, JSONArray ac * @param expected Expected JSONArray * @param actual JSONArray to compare * @param strict Enables strict checking - * @throws JSONException JSON parsing error */ - public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean strict) - throws JSONException { + public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean strict) { assertNotEquals(expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -752,10 +673,8 @@ public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean * @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 { + public static void assertNotEquals(String message, JSONArray expected, JSONArray actual, boolean strict) { assertNotEquals(message, expected, actual, strict ? JSONCompareMode.STRICT : JSONCompareMode.LENIENT); } @@ -766,10 +685,8 @@ public static void assertNotEquals(String message, JSONArray expected, JSONArray * @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 { + public static void assertEquals(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) { assertEquals("", expected, actual, compareMode); } @@ -781,10 +698,8 @@ public static void assertEquals(JSONArray expected, JSONArray actual, JSONCompar * @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 { + public static void assertEquals(String message, JSONArray expected, JSONArray actual, JSONCompareMode compareMode) { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); if (result.failed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); @@ -798,10 +713,8 @@ public static void assertEquals(String message, JSONArray expected, JSONArray ac * @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(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) - throws JSONException { + public static void assertNotEquals(JSONArray expected, JSONArray actual, JSONCompareMode compareMode) { assertNotEquals("", expected, actual, compareMode); } @@ -813,10 +726,9 @@ public static void assertNotEquals(JSONArray expected, JSONArray actual, JSONCom * @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 { + public static void assertNotEquals(String message, JSONArray expected, JSONArray actual, + JSONCompareMode compareMode) { JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); if (result.passed()) { throw new AssertionError(getCombinedMessage(message, result.getMessage())); diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java index b963be9f..c17115df 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompare.java @@ -15,7 +15,6 @@ package org.skyscreamer.jsonassert; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.json.JSONString; import org.skyscreamer.jsonassert.comparator.DefaultComparator; @@ -41,11 +40,9 @@ private static JSONComparator getComparatorForMode(JSONCompareMode mode) { * @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 { + public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONComparator comparator) { Object expected = JSONParser.parseJSON(expectedStr); Object actual = JSONParser.parseJSON(actualStr); if ((expected instanceof JSONObject) && (actual instanceof JSONObject)) { @@ -72,10 +69,8 @@ else if (expected instanceof JSONObject) { * @param actual actual json object * @param comparator comparator to use * @return result of the comparison - * @throws JSONException JSON parsing error */ - public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONComparator comparator) - throws JSONException { + public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONComparator comparator) { return comparator.compareJSON(expected, actual); } @@ -86,10 +81,8 @@ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actu * @param actual actual json array * @param comparator comparator to use * @return result of the comparison - * @throws JSONException JSON parsing error */ - public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONComparator comparator) - throws JSONException { + public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONComparator comparator) { return comparator.compareJSON(expected, actual); } @@ -118,10 +111,8 @@ public static JSONCompareResult compareJson(final JSONString expected, final JSO * @param actualStr JSON string to compare * @param mode Defines comparison behavior * @return result of the comparison - * @throws JSONException JSON parsing error */ - public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONCompareMode mode) - throws JSONException { + public static JSONCompareResult compareJSON(String expectedStr, String actualStr, JSONCompareMode mode) { return compareJSON(expectedStr, actualStr, getComparatorForMode(mode)); } @@ -132,10 +123,8 @@ public static JSONCompareResult compareJSON(String expectedStr, String actualStr * @param actual JSONObject to compare * @param mode Defines comparison behavior * @return result of the comparison - * @throws JSONException JSON parsing error */ - public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONCompareMode mode) - throws JSONException { + public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actual, JSONCompareMode mode) { return compareJSON(expected, actual, getComparatorForMode(mode)); } @@ -147,10 +136,8 @@ public static JSONCompareResult compareJSON(JSONObject expected, JSONObject actu * @param actual JSONArray to compare * @param mode Defines comparison behavior * @return result of the comparison - * @throws JSONException JSON parsing error */ - public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONCompareMode mode) - throws JSONException { + public static JSONCompareResult compareJSON(JSONArray expected, JSONArray actual, JSONCompareMode mode) { return compareJSON(expected, actual, getComparatorForMode(mode)); } diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONParser.java b/src/main/java/org/skyscreamer/jsonassert/JSONParser.java index 882d25da..a70af96c 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONParser.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONParser.java @@ -36,9 +36,8 @@ private JSONParser() {} * * @param s Raw JSON string to be parsed * @return JSONObject or JSONArray - * @throws JSONException JSON parsing error */ - public static Object parseJSON(final String s) throws JSONException { + public static Object parseJSON(final String s) { if (s.trim().startsWith("{")) { return new JSONObject(s); } diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java index 45b98a96..190e47ea 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/AbstractComparator.java @@ -15,7 +15,6 @@ package org.skyscreamer.jsonassert.comparator; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.JSONCompareResult; @@ -42,10 +41,9 @@ public AbstractComparator() { * * @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 { + public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) { JSONCompareResult result = new JSONCompareResult(); compareJSON("", expected, actual, result); return result; @@ -56,10 +54,9 @@ public final JSONCompareResult compareJSON(JSONObject expected, JSONObject actua * * @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 { + public final JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) { JSONCompareResult result = new JSONCompareResult(); compareJSONArray("", expected, actual, result); return result; @@ -86,9 +83,8 @@ protected void checkJsonObjectKeysActualInExpected(String prefix, JSONObject exp * @param expected * @param actual * @param result - * @throws JSONException */ - protected void checkJsonObjectKeysExpectedInActual(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) throws JSONException { + protected void checkJsonObjectKeysExpectedInActual(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) { Set expectedKeys = getKeys(expected); for (String key : expectedKeys) { Object expectedValue = expected.get(key); @@ -101,7 +97,7 @@ protected void checkJsonObjectKeysExpectedInActual(String prefix, JSONObject exp } } - protected void compareJSONArrayOfJsonObjects(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException { + protected void compareJSONArrayOfJsonObjects(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) { String uniqueKey = findUniqueKey(expected); if (uniqueKey == null || !isUsableAsUniqueKey(uniqueKey, actual)) { // An expensive last resort @@ -126,7 +122,7 @@ protected void compareJSONArrayOfJsonObjects(String key, JSONArray expected, JSO } } - protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException { + protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) { Map expectedCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(expected)); Map actualCount = JSONCompareUtil.getCardinalityMap(jsonArrayToList(actual)); for (Object o : expectedCount.keySet()) { @@ -144,7 +140,7 @@ protected void compareJSONArrayOfSimpleValues(String key, JSONArray expected, JS } } - protected void compareJSONArrayWithStrictOrder(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException { + protected void compareJSONArrayWithStrictOrder(String key, JSONArray expected, JSONArray actual, JSONCompareResult result) { for (int i = 0; i < expected.length(); ++i) { Object expectedValue = JSONCompareUtil.getObjectOrNull(expected, i); Object actualValue = JSONCompareUtil.getObjectOrNull(actual, i); @@ -157,7 +153,7 @@ protected void compareJSONArrayWithStrictOrder(String key, JSONArray expected, J // This is expensive (O(n^2) -- yuck), but may be the only resort for some cases with loose array ordering, and no // easy way to uniquely identify each element. protected void recursivelyCompareJSONArray(String key, JSONArray expected, JSONArray actual, - JSONCompareResult result) throws JSONException { + JSONCompareResult result) { Set matched = new HashSet(); for (int i = 0; i < expected.length(); ++i) { Object expectedElement = JSONCompareUtil.getObjectOrNull(expected, i); diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java index 35a62981..7e348b82 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java @@ -17,7 +17,6 @@ import java.text.MessageFormat; import org.json.JSONArray; -import org.json.JSONException; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.JSONCompareResult; @@ -69,7 +68,7 @@ public ArraySizeComparator(JSONCompareMode mode) { */ @Override public void compareJSONArray(String prefix, JSONArray expected, - JSONArray actual, JSONCompareResult result) throws JSONException { + JSONArray actual, JSONCompareResult result) { String arrayPrefix = prefix + "[]"; if (expected.length() < 1 || expected.length() > 2) { result.fail(MessageFormat diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java index ca326844..73337bdf 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java @@ -14,7 +14,6 @@ package org.skyscreamer.jsonassert.comparator; -import org.json.JSONException; import org.skyscreamer.jsonassert.Customization; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.JSONCompareResult; @@ -33,7 +32,7 @@ public CustomComparator(JSONCompareMode mode, Customization... customizations) } @Override - public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException { + public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) { Customization customization = getCustomization(prefix); if (customization != null) { try { diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java index bc71eae4..7d1bcc16 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java @@ -15,7 +15,6 @@ package org.skyscreamer.jsonassert.comparator; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.JSONCompareResult; @@ -36,8 +35,7 @@ public DefaultComparator(JSONCompareMode mode) { } @Override - public void compareJSON(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) - throws JSONException { + public void compareJSON(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) { // Check that actual contains all the expected values checkJsonObjectKeysExpectedInActual(prefix, expected, actual, result); @@ -48,8 +46,7 @@ public void compareJSON(String prefix, JSONObject expected, JSONObject actual, J } @Override - public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) - throws JSONException { + public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) { if (expectedValue == actualValue) { return; } @@ -74,8 +71,7 @@ public void compareValues(String prefix, Object expectedValue, Object actualValu } @Override - public void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result) - throws JSONException { + public void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result) { if (expected.length() != actual.length()) { result.fail(prefix + "[]: Expected " + expected.length() + " values but got " + actual.length()); return; diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java index 65ee88e5..9a78d493 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONComparator.java @@ -15,7 +15,6 @@ package org.skyscreamer.jsonassert.comparator; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.skyscreamer.jsonassert.JSONCompareResult; @@ -33,9 +32,8 @@ public interface JSONComparator { * @param expected the expected JSON object * @param actual the actual JSON object * @return the result of the comparison - * @throws JSONException JSON parsing error */ - JSONCompareResult compareJSON(JSONObject expected, JSONObject actual) throws JSONException; + JSONCompareResult compareJSON(JSONObject expected, JSONObject actual); /** * Compares two {@link JSONArray}s and returns the result of the comparison in a {@link JSONCompareResult} object. @@ -43,9 +41,8 @@ public interface JSONComparator { * @param expected the expected JSON array * @param actual the actual JSON array * @return the result of the comparison - * @throws JSONException JSON parsing error */ - JSONCompareResult compareJSON(JSONArray expected, JSONArray actual) throws JSONException; + JSONCompareResult compareJSON(JSONArray expected, JSONArray actual); /** * Compares two {@link JSONObject}s on the provided path represented by {@code prefix} and @@ -55,9 +52,8 @@ public interface JSONComparator { * @param expected the expected JSON object * @param actual the actual JSON object * @param result stores the actual state of the comparison result - * @throws JSONException JSON parsing error */ - void compareJSON(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result) throws JSONException; + void compareJSON(String prefix, JSONObject expected, JSONObject actual, JSONCompareResult result); /** * Compares two {@link Object}s on the provided path represented by {@code prefix} and @@ -67,9 +63,8 @@ public interface JSONComparator { * @param expectedValue the expected value * @param actualValue the actual value * @param result stores the actual state of the comparison result - * @throws JSONException JSON parsing error */ - void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException; + void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result); /** * Compares two {@link JSONArray}s on the provided path represented by {@code prefix} and @@ -79,7 +74,6 @@ public interface JSONComparator { * @param expected the expected JSON array * @param actual the actual JSON array * @param result stores the actual state of the comparison result - * @throws JSONException JSON parsing error */ - void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException; + void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result); } diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java index a6bcc4ce..8a7fe18d 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/JSONCompareUtil.java @@ -25,7 +25,6 @@ import java.util.TreeSet; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; /** @@ -44,9 +43,8 @@ private JSONCompareUtil() { * @param array the JSON array to convert * @param uniqueKey the key to map the JSON objects to * @return the map of {@link JSONObject}s from {@code array} - * @throws JSONException JSON parsing error */ - public static Map arrayOfJsonObjectToMap(JSONArray array, String uniqueKey) throws JSONException { + public static Map arrayOfJsonObjectToMap(JSONArray array, String uniqueKey) { Map valueMap = new HashMap(); for (int i = 0; i < array.length(); ++i) { JSONObject jsonObject = (JSONObject) array.get(i); @@ -61,9 +59,8 @@ public static Map arrayOfJsonObjectToMap(JSONArray array, St * * @param expected the array to find the unique key of * @return the unique key if there's any, otherwise null - * @throws JSONException JSON parsing error */ - public static String findUniqueKey(JSONArray expected) throws JSONException { + public static String findUniqueKey(JSONArray expected) { // Find a unique key for the object (id, name, whatever) JSONObject o = (JSONObject) expected.get(0); // There's at least one at this point for (String candidate : getKeys(o)) { @@ -86,9 +83,8 @@ public static String findUniqueKey(JSONArray expected) throws JSONException { * @param candidate is usable as a unique key if every element in the * @param array is a JSONObject having that key, and no two values are the same. * @return true if the candidate can work as a unique id across array - * @throws JSONException JSON parsing error */ - public static boolean isUsableAsUniqueKey(String candidate, JSONArray array) throws JSONException { + public static boolean isUsableAsUniqueKey(String candidate, JSONArray array) { Set seenValues = new HashSet(); for (int i = 0; i < array.length(); i++) { Object item = array.get(i); @@ -116,9 +112,8 @@ public static boolean isUsableAsUniqueKey(String candidate, JSONArray array) thr * * @param expected the JSON array to convert * @return the list of objects from the {@code expected} array - * @throws JSONException JSON parsing error */ - public static List jsonArrayToList(JSONArray expected) throws JSONException { + public static List jsonArrayToList(JSONArray expected) { List jsonObjects = new ArrayList(expected.length()); for (int i = 0; i < expected.length(); ++i) { jsonObjects.add(getObjectOrNull(expected, i)); @@ -132,9 +127,8 @@ public static List jsonArrayToList(JSONArray expected) throws JSONExcept * @param jsonArray the JSON array to get value from * @param index index of object to retrieve * @return value at the given index position - * @throws JSONException JSON parsing error */ - public static Object getObjectOrNull(JSONArray jsonArray, int index) throws JSONException { + public static Object getObjectOrNull(JSONArray jsonArray, int index) { return jsonArray.isNull(index) ? null : jsonArray.get(index); } @@ -143,10 +137,9 @@ public static Object getObjectOrNull(JSONArray jsonArray, int index) throws JSON * * @param array the JSON array to iterate through on * @return true if all the elements in {@code array} are simple values - * @throws JSONException JSON parsing error * @see #isSimpleValue(Object) */ - public static boolean allSimpleValues(JSONArray array) throws JSONException { + public static boolean allSimpleValues(JSONArray array) { for (int i = 0; i < array.length(); ++i) { if (!array.isNull(i) && !isSimpleValue(array.get(i))) { return false; @@ -170,9 +163,8 @@ public static boolean isSimpleValue(Object o) { * * @param array the array to inspect * @return true if all the elements in the given array are JSONObjects - * @throws JSONException JSON parsing error */ - public static boolean allJSONObjects(JSONArray array) throws JSONException { + public static boolean allJSONObjects(JSONArray array) { for (int i = 0; i < array.length(); ++i) { if (!(array.get(i) instanceof JSONObject)) { return false; @@ -186,9 +178,8 @@ public static boolean allJSONObjects(JSONArray array) throws JSONException { * * @param array the array to inspect * @return true if all the elements in the given array are JSONArrays - * @throws JSONException JSON parsing error */ - public static boolean allJSONArrays(JSONArray array) throws JSONException { + public static boolean allJSONArrays(JSONArray array) { for (int i = 0; i < array.length(); ++i) { if (!(array.get(i) instanceof JSONArray)) { return false; diff --git a/src/site/resources/index.html b/src/site/resources/index.html index 2bca2d18..97f11932 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

    Introduction

  • JUnit
  • -


    The current version of JSONassert is 1.5.3

    +


    The current version of JSONassert is 2.0.0-SNAPSHOT

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index 00b36f86..a7f45c50 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>1.5.3</version>
    +   <version>2.0.0-SNAPSHOT</version>
    </dependency>
    diff --git a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java index b7f29e1c..fa815d3c 100644 --- a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java @@ -21,7 +21,6 @@ import java.text.MessageFormat; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.junit.Test; import org.skyscreamer.jsonassert.comparator.ArraySizeComparator; @@ -43,12 +42,12 @@ public class ArrayValueMatcherTest { private static final JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT); private void doTest(String jsonPath, ArrayValueMatcher arrayValueMatcher, String expectedJSON, - String actualJSON) throws JSONException { + String actualJSON) { Customization customization = new Customization(jsonPath, arrayValueMatcher); JSONAssert.assertEquals(expectedJSON, actualJSON, new CustomComparator(JSONCompareMode.LENIENT, customization)); } - private void doFailingMatchTest(String jsonPath, ArrayValueMatcher arrayValueMatcher, String expectedJSON, String actualJSON, String expectedMessagePattern) throws JSONException { + private void doFailingMatchTest(String jsonPath, ArrayValueMatcher arrayValueMatcher, String expectedJSON, String actualJSON, String expectedMessagePattern) { try { doTest(jsonPath, arrayValueMatcher, expectedJSON, actualJSON); } @@ -61,12 +60,12 @@ private void doFailingMatchTest(String jsonPath, ArrayValueMatcher array } @Test - public void matchesSecondElementOfJSONObjectArray() throws JSONException { + public void matchesSecondElementOfJSONObjectArray() { doTest("a", new ArrayValueMatcher(comparator, 1), "{a:[{background:grey,id:2,type:row}]}", ARRAY_OF_JSONOBJECTS); } @Test - public void failsWhenSecondElementOfJSONObjectArrayDoesNotMatch() throws JSONException { + public void failsWhenSecondElementOfJSONObjectArrayDoesNotMatch() { doFailingMatchTest("a", new ArrayValueMatcher(comparator, 1), "{a:[{background:DOES_NOT_MATCH,id:2,type:row}]}", @@ -75,7 +74,7 @@ public void failsWhenSecondElementOfJSONObjectArrayDoesNotMatch() throws JSONExc } @Test - public void failsWhenThirdElementOfJSONObjectArrayDoesNotMatchInMultiplePlaces() throws JSONException { + public void failsWhenThirdElementOfJSONObjectArrayDoesNotMatchInMultiplePlaces() { doFailingMatchTest("a", new ArrayValueMatcher(comparator, 2), "{a:[{background:DOES_NOT_MATCH,id:3,type:WRONG_TYPE}]}", @@ -84,7 +83,7 @@ public void failsWhenThirdElementOfJSONObjectArrayDoesNotMatchInMultiplePlaces() } @Test - public void failsWhenTwoElementsOfJSONObjectArrayDoNotMatch() throws JSONException { + public void failsWhenTwoElementsOfJSONObjectArrayDoNotMatch() { doFailingMatchTest("a", new ArrayValueMatcher(comparator, 1, 2), "{a:[{background:DOES_NOT_MATCH,id:2,type:row},{background:white,id:3,type:WRONG_TYPE}]}", @@ -93,29 +92,29 @@ public void failsWhenTwoElementsOfJSONObjectArrayDoNotMatch() throws JSONExcepti } @Test - public void matchesThirdElementOfSimpleValueArray() throws JSONException { + public void matchesThirdElementOfSimpleValueArray() { doTest("a", new ArrayValueMatcher(comparator, 2), "{a:[3]}", ARRAY_OF_INTEGERS); } @Test - public void failsWhenTwoElementOfSimpleValueArrayDoNotMatch() throws JSONException { + public void failsWhenTwoElementOfSimpleValueArrayDoNotMatch() { doFailingMatchTest("a", new ArrayValueMatcher(comparator, 3, 4), "{a:[3,4]}", ARRAY_OF_INTEGERS, "a\\[3\\]\\s*Expected:\\s3\\s*got:\\s*4\\s*;\\s*a\\[4\\]\\s*Expected:\\s*4\\s*got:\\s*5\\s*"); } @Test - public void matchesFirstElementOfArrayOfJSONArrays() throws JSONException { + public void matchesFirstElementOfArrayOfJSONArrays() { doTest("a", new ArrayValueMatcher(comparator, 0), "{a:[[6,7,8]]}", ARRAY_OF_JSONARRAYS); } @Test - public void matchesSizeOfFirstThreeInnerArrays() throws JSONException { + public void matchesSizeOfFirstThreeInnerArrays() { JSONComparator innerArraySizeComparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER); doTest("a", new ArrayValueMatcher(innerArraySizeComparator, 0, 2), "{a:[[3]]}", ARRAY_OF_JSONARRAYS); } @Test - public void failsWhenInnerArraySizeDoesNotMatch() throws JSONException { + public void failsWhenInnerArraySizeDoesNotMatch() { JSONComparator innerArraySizeComparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER); doFailingMatchTest("a", new ArrayValueMatcher(innerArraySizeComparator), @@ -125,7 +124,7 @@ public void failsWhenInnerArraySizeDoesNotMatch() throws JSONException { } @Test - public void failsWhenInnerJSONObjectArrayElementDoesNotMatch() throws JSONException { + public void failsWhenInnerJSONObjectArrayElementDoesNotMatch() { ArrayValueMatcher innerArrayValueMatcher = new ArrayValueMatcher(comparator, 1); JSONComparator innerArrayComparator = new CustomComparator( JSONCompareMode.LENIENT, new Customization("a[2]", innerArrayValueMatcher)); @@ -137,12 +136,12 @@ public void failsWhenInnerJSONObjectArrayElementDoesNotMatch() throws JSONExcept } @Test - public void matchesEveryElementOfJSONObjectArray() throws JSONException { + public void matchesEveryElementOfJSONObjectArray() { doTest("a", new ArrayValueMatcher(comparator), "{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS); } @Test - public void failsWhenNotEveryElementOfJSONObjectArrayMatches() throws JSONException { + public void failsWhenNotEveryElementOfJSONObjectArrayMatches() { doFailingMatchTest("a", new ArrayValueMatcher(comparator), "{a:[{background:white}]}", @@ -151,22 +150,22 @@ public void failsWhenNotEveryElementOfJSONObjectArrayMatches() throws JSONExcept } @Test - public void matchesEveryElementOfJSONObjectArrayWhenRangeTooLarge() throws JSONException { + public void matchesEveryElementOfJSONObjectArrayWhenRangeTooLarge() { doTest("a", new ArrayValueMatcher(comparator, 0, 500), "{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS); } @Test - public void matchesElementPairsStartingFromElement1OfJSONObjectArrayWhenRangeTooLarge() throws JSONException { + public void matchesElementPairsStartingFromElement1OfJSONObjectArrayWhenRangeTooLarge() { doTest("a", new ArrayValueMatcher(comparator, 1, 500), "{a:[{background:grey},{background:white}]}", ARRAY_OF_JSONOBJECTS); } @Test - public void matchesElementPairsStartingFromElement0OfJSONObjectArrayWhenRangeTooLarge() throws JSONException { + public void matchesElementPairsStartingFromElement0OfJSONObjectArrayWhenRangeTooLarge() { doTest("a", new ArrayValueMatcher(comparator), "{a:[{background:white},{background:grey}]}", ARRAY_OF_JSONOBJECTS); } @Test - public void failsWhenAppliedToNonArray() throws JSONException { + public void failsWhenAppliedToNonArray() { try { doTest("a", new ArrayValueMatcher(comparator), "{a:[{background:white}]}", "{a:{attr1:value1,attr2:value2}}"); } @@ -185,12 +184,12 @@ public void failsWhenAppliedToNonArray() throws JSONException { */ @Test - public void simpleValueMatchesSecondElementOfJSONObjectArray() throws JSONException { + public void simpleValueMatchesSecondElementOfJSONObjectArray() { doTest("a", new ArrayValueMatcher(comparator, 3), "{a:4}", ARRAY_OF_INTEGERS); } @Test - public void jsonObjectMatchesSecondElementOfJSONObjectArray() throws JSONException { + public void jsonObjectMatchesSecondElementOfJSONObjectArray() { doTest("a", new ArrayValueMatcher(comparator, 1), "{a:{background:grey,id:2,type:row}}", ARRAY_OF_JSONOBJECTS); } @@ -198,35 +197,35 @@ public void jsonObjectMatchesSecondElementOfJSONObjectArray() throws JSONExcepti * Following tests contain copies of code quoted in ArrayValueMatcher JavaDoc and are included to verify that the exact code documented works as expected. */ @Test - public void verifyIdAttributeOfFirstArrayElementMatches() throws JSONException { + public void verifyIdAttributeOfFirstArrayElementMatches() { JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT); Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 0)); JSONAssert.assertEquals("{a:[{id:1}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); } @Test - public void verifyIdAttributeOfFirstArrayElementMatchesSimplifiedExpectedSyntax() throws JSONException { + public void verifyIdAttributeOfFirstArrayElementMatchesSimplifiedExpectedSyntax() { JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT); Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 0)); JSONAssert.assertEquals("{a:{id:1}}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); } @Test - public void verifyTypeAttributeOfSecondAndThirdElementMatchesRow() throws JSONException { + public void verifyTypeAttributeOfSecondAndThirdElementMatchesRow() { JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT); Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 1, 2)); JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); } @Test - public void verifyTypeAttributeOfEveryArrayElementMatchesRow() throws JSONException { + public void verifyTypeAttributeOfEveryArrayElementMatchesRow() { JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT); Customization customization = new Customization("a", new ArrayValueMatcher(comparator)); JSONAssert.assertEquals("{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); } @Test - public void verifyEveryArrayElementWithCustomComparator() throws JSONException { + public void verifyEveryArrayElementWithCustomComparator() { // get length of array we will verify int aLength = ((JSONArray)((JSONObject)JSONParser.parseJSON(ARRAY_OF_JSONOBJECTS)).get("a")).length(); // create array of customizations one for each array element @@ -245,21 +244,21 @@ public void verifyEveryArrayElementWithCustomComparator() throws JSONException { } @Test - public void verifyBackgroundAttributesOfEveryArrayElementAlternateBetweenWhiteAndGrey() throws JSONException { + public void verifyBackgroundAttributesOfEveryArrayElementAlternateBetweenWhiteAndGrey() { JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT); Customization customization = new Customization("a", new ArrayValueMatcher(comparator)); JSONAssert.assertEquals("{a:[{background:white},{background:grey}]}", ARRAY_OF_JSONOBJECTS, new CustomComparator(JSONCompareMode.LENIENT, customization)); } @Test - public void verifyEveryElementOfArrayIsJSONArrayOfLength3() throws JSONException { + public void verifyEveryElementOfArrayIsJSONArrayOfLength3() { JSONComparator comparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER); Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 0, 2)); JSONAssert.assertEquals("{a:[[3]]}", ARRAY_OF_JSONARRAYS, new CustomComparator(JSONCompareMode.LENIENT, customization)); } @Test - public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9() throws JSONException { + public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9() { Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher(comparator, 0)); JSONComparator comparator = new CustomComparator(JSONCompareMode.LENIENT, innerCustomization); Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 1)); @@ -267,7 +266,7 @@ public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9() throws J } @Test - public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9WithSimpliedExpectedString() throws JSONException { + public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9WithSimpliedExpectedString() { Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher(comparator, 0)); JSONComparator comparator = new CustomComparator(JSONCompareMode.LENIENT, innerCustomization); Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 1)); @@ -275,7 +274,7 @@ public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9WithSimplie } @Test - public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9WithEvenMoreSimpliedExpectedString() throws JSONException { + public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9WithEvenMoreSimpliedExpectedString() { Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher(comparator, 0)); JSONComparator comparator = new CustomComparator(JSONCompareMode.LENIENT, innerCustomization); Customization customization = new Customization("a", new ArrayValueMatcher(comparator, 1)); diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONArrayWithNullTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONArrayWithNullTest.java index c5a5da5f..0bf11531 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONArrayWithNullTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONArrayWithNullTest.java @@ -1,13 +1,12 @@ package org.skyscreamer.jsonassert; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.junit.Test; public class JSONArrayWithNullTest { @Test - public void testJSONArrayWithNullValue() throws JSONException { + public void testJSONArrayWithNullValue() { JSONArray jsonArray1 = getJSONArray1(); JSONArray jsonArray2 = getJSONArray2(); @@ -16,7 +15,7 @@ public void testJSONArrayWithNullValue() throws JSONException { } @Test - public void testJSONArrayWithNullValueAndJsonObject() throws JSONException { + public void testJSONArrayWithNullValueAndJsonObject() { JSONArray jsonArray1 = getJSONArray1(); JSONObject jsonObject1 = new JSONObject(); jsonObject1.put("hey", "value"); @@ -32,7 +31,7 @@ public void testJSONArrayWithNullValueAndJsonObject() throws JSONException { private JSONArray getJSONArray1() { JSONArray jsonArray1 = new JSONArray(); jsonArray1.put(1); - jsonArray1.put(null); + jsonArray1.put(JSONObject.NULL); jsonArray1.put(3); jsonArray1.put(2); return jsonArray1; @@ -41,7 +40,7 @@ private JSONArray getJSONArray1() { private JSONArray getJSONArray2() { JSONArray jsonArray1 = new JSONArray(); jsonArray1.put(1); - jsonArray1.put(null); + jsonArray1.put(JSONObject.NULL); jsonArray1.put(3); jsonArray1.put(2); return jsonArray1; diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java index e39c80ba..e17f684b 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java @@ -24,7 +24,6 @@ import java.util.Arrays; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; import org.junit.Assert; import org.junit.Test; @@ -36,7 +35,7 @@ */ public class JSONAssertTest { @Test - public void testString() throws JSONException { + public void testString() { testPass("\"Joe\"", "\"Joe\"", STRICT); testPass("\"Joe\"", "\"Joe\"", LENIENT); testPass("\"Joe\"", "\"Joe\"", NON_EXTENSIBLE); @@ -48,7 +47,7 @@ public void testString() throws JSONException { } @Test - public void testNumber() throws JSONException { + public void testNumber() { testPass("123", "123", STRICT); testPass("123", "123", LENIENT); testPass("123", "123", NON_EXTENSIBLE); @@ -66,7 +65,7 @@ public void testNumber() throws JSONException { } @Test - public void testSimple() throws JSONException { + public void testSimple() { testPass("{id:1}", "{id:1}", STRICT); testFail("{id:1}", "{id:2}", STRICT); testPass("{id:1}", "{id:1}", LENIENT); @@ -78,7 +77,7 @@ public void testSimple() throws JSONException { } @Test - public void testSimpleStrict() throws JSONException { + public void testSimpleStrict() { testPass("{id:1}", "{id:1,name:\"Joe\"}", LENIENT); testFail("{id:1}", "{id:1,name:\"Joe\"}", STRICT); testPass("{id:1}", "{id:1,name:\"Joe\"}", STRICT_ORDER); @@ -86,7 +85,7 @@ public void testSimpleStrict() throws JSONException { } @Test - public void testReversed() throws JSONException { + public void testReversed() { testPass("{name:\"Joe\",id:1}", "{id:1,name:\"Joe\"}", LENIENT); testPass("{name:\"Joe\",id:1}", "{id:1,name:\"Joe\"}", STRICT); testPass("{name:\"Joe\",id:1}", "{id:1,name:\"Joe\"}", NON_EXTENSIBLE); @@ -94,7 +93,7 @@ public void testReversed() throws JSONException { } @Test // Currently JSONAssert assumes JSONObject. - public void testArray() throws JSONException { + public void testArray() { testPass("[1,2,3]","[1,2,3]", STRICT); testPass("[1,2,3]","[1,3,2]", LENIENT); testFail("[1,2,3]","[1,3,2]", STRICT); @@ -106,7 +105,7 @@ public void testArray() throws JSONException { } @Test - public void testNested() throws JSONException { + public void testNested() { testPass("{id:1,address:{addr1:\"123 Main\", addr2:null, city:\"Houston\", state:\"TX\"}}", "{id:1,address:{addr1:\"123 Main\", addr2:null, city:\"Houston\", state:\"TX\"}}", STRICT); testFail("{id:1,address:{addr1:\"123 Main\", addr2:null, city:\"Houston\", state:\"TX\"}}", @@ -114,7 +113,7 @@ public void testNested() throws JSONException { } @Test - public void testVeryNested() throws JSONException { + public void testVeryNested() { testPass("{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:\"blah\"}}}}}}}}}}}}}}}}", "{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:\"blah\"}}}}}}}}}}}}}}}}", STRICT); testFail("{a:{b:{c:{d:{e:{f:{g:{h:{i:{j:{k:{l:{m:{n:{o:{p:\"blah\"}}}}}}}}}}}}}}}}", @@ -122,7 +121,7 @@ public void testVeryNested() throws JSONException { } @Test - public void testSimpleArray() throws JSONException { + public void testSimpleArray() { testPass("{id:1,pets:[\"dog\",\"cat\",\"fish\"]}", // Exact to exact (strict) "{id:1,pets:[\"dog\",\"cat\",\"fish\"]}", STRICT); @@ -153,40 +152,40 @@ public void testSimpleArray() throws JSONException { } @Test - public void testSimpleMixedArray() throws JSONException { + public void testSimpleMixedArray() { testPass("{stuff:[321, \"abc\"]}", "{stuff:[\"abc\", 321]}", LENIENT); testFail("{stuff:[321, \"abc\"]}", "{stuff:[\"abc\", 789]}", LENIENT); } @Test - public void testComplexMixedStrictArray() throws JSONException { + public void testComplexMixedStrictArray() { testPass("{stuff:[{pet:\"cat\"},{car:\"Ford\"}]}", "{stuff:[{pet:\"cat\"},{car:\"Ford\"}]}", STRICT); } @Test - public void testComplexMixedArray() throws JSONException { + public void testComplexMixedArray() { testPass("{stuff:[{pet:\"cat\"},{car:\"Ford\"}]}", "{stuff:[{pet:\"cat\"},{car:\"Ford\"}]}", LENIENT); } @Test - public void testComplexArrayNoUniqueID() throws JSONException { + public void testComplexArrayNoUniqueID() { testPass("{stuff:[{address:{addr1:\"123 Main\"}}, {address:{addr1:\"234 Broad\"}}]}", "{stuff:[{address:{addr1:\"123 Main\"}}, {address:{addr1:\"234 Broad\"}}]}", LENIENT); } @Test - public void testSimpleAndComplexStrictArray() throws JSONException { + public void testSimpleAndComplexStrictArray() { testPass("{stuff:[123,{a:\"b\"}]}", "{stuff:[123,{a:\"b\"}]}", STRICT); } @Test - public void testSimpleAndComplexArray() throws JSONException { + public void testSimpleAndComplexArray() { testPass("{stuff:[123,{a:\"b\"}]}", "{stuff:[123,{a:\"b\"}]}", LENIENT); } @Test - public void testComplexArray() throws JSONException { + public void testComplexArray() { testPass("{id:1,name:\"Joe\",friends:[{id:2,name:\"Pat\",pets:[\"dog\"]},{id:3,name:\"Sue\",pets:[\"bird\",\"fish\"]}],pets:[]}", "{id:1,name:\"Joe\",friends:[{id:2,name:\"Pat\",pets:[\"dog\"]},{id:3,name:\"Sue\",pets:[\"bird\",\"fish\"]}],pets:[]}", STRICT); // Exact to exact (strict) @@ -217,23 +216,23 @@ public void testComplexArray() throws JSONException { } @Test - public void testArrayOfArraysStrict() throws JSONException { + public void testArrayOfArraysStrict() { testPass("{id:1,stuff:[[1,2],[2,3],[],[3,4]]}", "{id:1,stuff:[[1,2],[2,3],[],[3,4]]}", STRICT); testFail("{id:1,stuff:[[1,2],[2,3],[3,4],[]]}", "{id:1,stuff:[[1,2],[2,3],[],[3,4]]}", STRICT); } @Test - public void testArrayOfArrays() throws JSONException { + public void testArrayOfArrays() { testPass("{id:1,stuff:[[4,3],[3,2],[],[1,2]]}", "{id:1,stuff:[[1,2],[2,3],[],[3,4]]}", LENIENT); } @Test - public void testLenientArrayRecursion() throws JSONException { + public void testLenientArrayRecursion() { testPass("[{\"arr\":[5, 2, 1]}]", "[{\"b\":3, \"arr\":[1, 5, 2]}]", LENIENT); } @Test - public void testFieldMismatch() throws JSONException { + public void testFieldMismatch() { JSONCompareResult result = JSONCompare.compareJSON("{name:\"Pat\"}", "{name:\"Sue\"}", STRICT); FieldComparisonFailure comparisonFailure = result.getFieldFailures().iterator().next(); Assert.assertEquals("Pat", comparisonFailure.getExpected()); @@ -242,7 +241,7 @@ public void testFieldMismatch() throws JSONException { } @Test - public void testBooleanArray() throws JSONException { + public void testBooleanArray() { testPass("[true, false, true, true, false]", "[true, false, true, true, false]", STRICT); testPass("[false, true, true, false, true]", "[true, false, true, true, false]", LENIENT); testFail("[false, true, true, false, true]", "[true, false, true, true, false]", STRICT); @@ -251,34 +250,34 @@ public void testBooleanArray() throws JSONException { } @Test - public void testNullProperty() throws JSONException { + public void testNullProperty() { testFail("{id:1,name:\"Joe\"}", "{id:1,name:null}", STRICT); testFail("{id:1,name:null}", "{id:1,name:\"Joe\"}", STRICT); } @Test - public void testIncorrectTypes() throws JSONException { + public void testIncorrectTypes() { testFail("{id:1,name:\"Joe\"}", "{id:1,name:[]}", STRICT); testFail("{id:1,name:[]}", "{id:1,name:\"Joe\"}", STRICT); } @Test - public void testNullEquality() throws JSONException { + public void testNullEquality() { testPass("{id:1,name:null}", "{id:1,name:null}", STRICT); } @Test - public void testExpectedArrayButActualObject() throws JSONException { + public void testExpectedArrayButActualObject() { testFail("[1]", "{id:1}", LENIENT); } @Test - public void testExpectedObjectButActualArray() throws JSONException { + public void testExpectedObjectButActualArray() { testFail("{id:1}", "[1]", LENIENT); } @Test - public void testEquivalentIntAndLong() throws JSONException { + public void testEquivalentIntAndLong() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -288,7 +287,7 @@ public void testEquivalentIntAndLong() throws JSONException { } @Test - public void testEquivalentIntAndDouble() throws JSONException { + public void testEquivalentIntAndDouble() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -298,7 +297,7 @@ public void testEquivalentIntAndDouble() throws JSONException { } @Test(expected = AssertionError.class) - public void testAssertNotEqualsWhenEqualStrict() throws JSONException { + public void testAssertNotEqualsWhenEqualStrict() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -307,7 +306,7 @@ public void testAssertNotEqualsWhenEqualStrict() throws JSONException { } @Test(expected = AssertionError.class) - public void testAssertNotEqualsWhenEqualLenient() throws JSONException { + public void testAssertNotEqualsWhenEqualLenient() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -316,7 +315,7 @@ public void testAssertNotEqualsWhenEqualLenient() throws JSONException { } @Test() - public void testAssertNotEqualsWhenEqualDiffObjectsStrict() throws JSONException { + public void testAssertNotEqualsWhenEqualDiffObjectsStrict() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -326,7 +325,7 @@ public void testAssertNotEqualsWhenEqualDiffObjectsStrict() throws JSONException } @Test(expected = AssertionError.class) - public void testAssertNotEqualsWhenEqualDiffObjectsLenient() throws JSONException { + public void testAssertNotEqualsWhenEqualDiffObjectsLenient() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -337,7 +336,7 @@ public void testAssertNotEqualsWhenEqualDiffObjectsLenient() throws JSONExceptio } @Test() - public void testAssertNotEqualsWhenDifferentStrict() throws JSONException { + public void testAssertNotEqualsWhenDifferentStrict() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -346,7 +345,7 @@ public void testAssertNotEqualsWhenDifferentStrict() throws JSONException { } @Test() - public void testAssertNotEqualsWhenDifferentLenient() throws JSONException { + public void testAssertNotEqualsWhenDifferentLenient() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -355,7 +354,7 @@ public void testAssertNotEqualsWhenDifferentLenient() throws JSONException { } @Test() - public void testAssertNotEqualsString() throws JSONException { + public void testAssertNotEqualsString() { JSONAssert.assertNotEquals("[1,2,3]", "[1,3,2]", STRICT); JSONAssert.assertNotEquals("[1,2,3]", "[1,2,4]", LENIENT); JSONAssert.assertNotEquals("[1,2,3]", "[1,3,2]", true); @@ -363,7 +362,7 @@ public void testAssertNotEqualsString() throws JSONException { } @Test() - public void testAssertEqualsString() throws JSONException { + public void testAssertEqualsString() { JSONAssert.assertEquals("[1,2,3]", "[1,2,3]", true); JSONAssert.assertEquals("{id:12345}", "{id:12345}", false); JSONAssert.assertEquals("{id:12345}", "{id:12345, name:\"john\"}", LENIENT); @@ -372,7 +371,7 @@ public void testAssertEqualsString() throws JSONException { } @Test() - public void testAssertNotEqualsStringAndJSONObject() throws JSONException { + public void testAssertNotEqualsStringAndJSONObject() { JSONObject actual = new JSONObject(); actual.put("id", Double.valueOf(12345)); JSONAssert.assertEquals("{id:12345}", actual, false); @@ -380,7 +379,7 @@ public void testAssertNotEqualsStringAndJSONObject() throws JSONException { } @Test() - public void testAssertNotEqualsJSONArray() throws JSONException { + public void testAssertNotEqualsJSONArray() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("[1,2,3]", actual, false); JSONAssert.assertNotEquals("[1,2,4]", actual, false); @@ -390,7 +389,7 @@ public void testAssertNotEqualsJSONArray() throws JSONException { } @Test - public void testAssertEqualsStringJSONArrayBooleanWithMessage() throws JSONException { + public void testAssertEqualsStringJSONArrayBooleanWithMessage() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("Message", "[1,2,3]", actual, false); performAssertEqualsTestForMessageVerification("[1,2,4]", actual, false); @@ -398,7 +397,7 @@ public void testAssertEqualsStringJSONArrayBooleanWithMessage() throws JSONExcep } @Test - public void testAssertEqualsStringJSONArrayCompareModeWithMessage() throws JSONException { + public void testAssertEqualsStringJSONArrayCompareModeWithMessage() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("Message", "[1,2,3]", actual, LENIENT); performAssertEqualsTestForMessageVerification("[1,2,4]", actual, LENIENT); @@ -406,7 +405,7 @@ public void testAssertEqualsStringJSONArrayCompareModeWithMessage() throws JSONE } @Test - public void testAssertEqualsJSONArray2BooleanWithMessage() throws JSONException { + public void testAssertEqualsJSONArray2BooleanWithMessage() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("Message", new JSONArray(Arrays.asList(1, 2, 3)), actual, false); performAssertEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 2, 4)), actual, false); @@ -414,7 +413,7 @@ public void testAssertEqualsJSONArray2BooleanWithMessage() throws JSONException } @Test - public void testAssertEqualsJSONArray2JSONCompareWithMessage() throws JSONException { + public void testAssertEqualsJSONArray2JSONCompareWithMessage() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertEquals("Message", new JSONArray(Arrays.asList(1, 2, 3)), actual, LENIENT); @@ -423,7 +422,7 @@ public void testAssertEqualsJSONArray2JSONCompareWithMessage() throws JSONExcept } @Test - public void testAssertEqualsString2Boolean() throws JSONException { + public void testAssertEqualsString2Boolean() { JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345}", false); JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345, name:\"john\"}", false); @@ -432,7 +431,7 @@ public void testAssertEqualsString2Boolean() throws JSONException { } @Test - public void testAssertEqualsString2JSONCompare() throws JSONException { + public void testAssertEqualsString2JSONCompare() { JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345}", LENIENT); JSONAssert.assertEquals("Message", "{id:12345}", "{id:12345, name:\"john\"}", LENIENT); @@ -441,7 +440,7 @@ public void testAssertEqualsString2JSONCompare() throws JSONException { } @Test - public void testAssertEqualsStringJSONObjectBoolean() throws JSONException { + public void testAssertEqualsStringJSONObjectBoolean() { JSONObject actual = new JSONObject(); actual.put("id", Double.valueOf(12345)); JSONAssert.assertEquals("Message", "{id:12345}", actual, false); @@ -450,7 +449,7 @@ public void testAssertEqualsStringJSONObjectBoolean() throws JSONException { } @Test - public void testAssertEqualsStringJSONObjectJSONCompare() throws JSONException { + public void testAssertEqualsStringJSONObjectJSONCompare() { JSONObject actual = new JSONObject(); actual.put("id", Double.valueOf(12345)); JSONAssert.assertEquals("Message", "{id:12345}", actual, LENIENT); @@ -459,7 +458,7 @@ public void testAssertEqualsStringJSONObjectJSONCompare() throws JSONException { } @Test - public void testAssertEqualsJSONObject2JSONCompare() throws JSONException { + public void testAssertEqualsJSONObject2JSONCompare() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -478,7 +477,7 @@ public void testAssertEqualsJSONObject2JSONCompare() throws JSONException { } @Test - public void testAssertEqualsJSONObject2Boolean() throws JSONException { + public void testAssertEqualsJSONObject2Boolean() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -497,15 +496,15 @@ public void testAssertEqualsJSONObject2Boolean() throws JSONException { } @Test - public void testAssertEqualsString2JsonComparator() throws IllegalArgumentException, JSONException { - JSONAssert.assertEquals("Message", "{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":2}}", + public void testAssertEqualsString2JsonComparator() throws IllegalArgumentException { + JSONAssert.assertEquals("Message", "{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1}}", new CustomComparator( JSONCompareMode.STRICT, new Customization("entry.id", new RegularExpressionValueMatcher("\\d")) )); - performAssertEqualsTestForMessageVerification("{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":as}}", + performAssertEqualsTestForMessageVerification("{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":NOT_A_NUMBER}}", new CustomComparator( JSONCompareMode.STRICT, new Customization("entry.id", @@ -514,7 +513,7 @@ public void testAssertEqualsString2JsonComparator() throws IllegalArgumentExcept } @Test - public void testAssertNotEqualsStringJSONArrayBooleanWithMessage() throws JSONException { + public void testAssertNotEqualsStringJSONArrayBooleanWithMessage() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertNotEquals("Message", "[1,4,3]", actual, false); JSONAssert.assertNotEquals("Message", "[1,4,3]", actual, true); @@ -523,7 +522,7 @@ public void testAssertNotEqualsStringJSONArrayBooleanWithMessage() throws JSONEx } @Test - public void testAssertNotEqualsStringJSONArrayCompareModeWithMessage() throws JSONException { + public void testAssertNotEqualsStringJSONArrayCompareModeWithMessage() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertNotEquals("Message", "[1,2,4]", actual, LENIENT); JSONAssert.assertNotEquals("Message", "[1,2,4]", actual, STRICT); @@ -532,7 +531,7 @@ public void testAssertNotEqualsStringJSONArrayCompareModeWithMessage() throws JS } @Test - public void testAssertNotEqualsJSONArray2BooleanWithMessage() throws JSONException { + public void testAssertNotEqualsJSONArray2BooleanWithMessage() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertNotEquals("Message", new JSONArray(Arrays.asList(1, 4, 3)), actual, false); performAssertNotEqualsTestForMessageVerification(new JSONArray(Arrays.asList(1, 3, 2)), actual, false); @@ -540,7 +539,7 @@ public void testAssertNotEqualsJSONArray2BooleanWithMessage() throws JSONExcepti } @Test - public void testAssertNotEqualsJSONArray2JSONCompareWithMessage() throws JSONException { + public void testAssertNotEqualsJSONArray2JSONCompareWithMessage() { JSONArray actual = new JSONArray(Arrays.asList(1, 2, 3)); JSONAssert.assertNotEquals("Message", new JSONArray(Arrays.asList(1, 4, 3)), actual, LENIENT); @@ -549,7 +548,7 @@ public void testAssertNotEqualsJSONArray2JSONCompareWithMessage() throws JSONExc } @Test - public void testAssertNotEqualsString2Boolean() throws JSONException { + public void testAssertNotEqualsString2Boolean() { JSONAssert.assertNotEquals("Message", "{id:12345}", "{id:45}", false); JSONAssert.assertNotEquals("Message", "{id:12345}", "{id:345, name:\"john\"}", false); @@ -558,7 +557,7 @@ public void testAssertNotEqualsString2Boolean() throws JSONException { } @Test - public void testAssertNotEqualsString2JSONCompare() throws JSONException { + public void testAssertNotEqualsString2JSONCompare() { JSONAssert.assertNotEquals("Message", "{id:12345}", "{id:123}", LENIENT); JSONAssert.assertNotEquals("Message", "{id:12345, name:\"John\"}", "{id:12345}", LENIENT); @@ -567,7 +566,7 @@ public void testAssertNotEqualsString2JSONCompare() throws JSONException { } @Test - public void testAssertNotEqualsStringJSONObjectBoolean() throws JSONException { + public void testAssertNotEqualsStringJSONObjectBoolean() { JSONObject actual = new JSONObject(); actual.put("id", Double.valueOf(12345)); JSONAssert.assertNotEquals("Message", "{id:1234}", actual, false); @@ -576,7 +575,7 @@ public void testAssertNotEqualsStringJSONObjectBoolean() throws JSONException { } @Test - public void testAssertNotEqualsStringJSONObjectJSONCompare() throws JSONException { + public void testAssertNotEqualsStringJSONObjectJSONCompare() { JSONObject actual = new JSONObject(); actual.put("id", Double.valueOf(12345)); JSONAssert.assertNotEquals("Message", "{id:1234}", actual, LENIENT); @@ -585,7 +584,7 @@ public void testAssertNotEqualsStringJSONObjectJSONCompare() throws JSONExceptio } @Test - public void testAssertNtEqualsJSONObject2JSONCompare() throws JSONException { + public void testAssertNtEqualsJSONObject2JSONCompare() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -605,7 +604,7 @@ public void testAssertNtEqualsJSONObject2JSONCompare() throws JSONException { } @Test - public void testAssertNotEqualsJSONObject2Boolean() throws JSONException { + public void testAssertNotEqualsJSONObject2Boolean() { JSONObject expected = new JSONObject(); JSONObject actual = new JSONObject(); expected.put("id", Integer.valueOf(12345)); @@ -625,15 +624,15 @@ public void testAssertNotEqualsJSONObject2Boolean() throws JSONException { } @Test - public void testAssertNotEqualsString2JsonComparator() throws IllegalArgumentException, JSONException { - JSONAssert.assertNotEquals("Message", "{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":hh}}", + public void testAssertNotEqualsString2JsonComparator() throws IllegalArgumentException { + JSONAssert.assertNotEquals("Message", "{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":NOT_A_NUMBER}}", new CustomComparator( JSONCompareMode.STRICT, new Customization("entry.id", new RegularExpressionValueMatcher("\\d")) )); - performAssertNotEqualsTestForMessageVerification("{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1, \"id\":2}}", + performAssertNotEqualsTestForMessageVerification("{\"entry\":{\"id\":x}}", "{\"entry\":{\"id\":1}}", new CustomComparator( JSONCompareMode.STRICT, new Customization("entry.id", @@ -642,7 +641,6 @@ public void testAssertNotEqualsString2JsonComparator() throws IllegalArgumentExc } private void testPass(String expected, String actual, JSONCompareMode compareMode) - throws JSONException { String message = expected + " == " + actual + " (" + compareMode + ")"; JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); @@ -650,7 +648,6 @@ private void testPass(String expected, String actual, JSONCompareMode compareMod } private void testFail(String expected, String actual, JSONCompareMode compareMode) - throws JSONException { String message = expected + " != " + actual + " (" + compareMode + ")"; JSONCompareResult result = JSONCompare.compareJSON(expected, actual, compareMode); @@ -660,7 +657,7 @@ private void testFail(String expected, String actual, JSONCompareMode compareMod private void performAssertEqualsTestForMessageVerification( Object expected, Object actual, - Object strictMode) throws JSONException { + Object strictMode) { String message = "Message"; String testShouldFailMessage = "The test should fail so that the message in AssertionError could be verified."; @@ -754,7 +751,7 @@ private void performAssertNotEqualsTestForMessageVerification( Object expected, Object actual, Object strictMode) - throws JSONException { + { String message = "Message"; String testShouldFailMessage = "The test should fail so that the message in AssertionError could be verified."; diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java index 450adfde..17c20972 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java @@ -24,7 +24,6 @@ import org.hamcrest.Description; import org.hamcrest.Matcher; -import org.json.JSONException; import org.junit.Test; import org.junit.internal.matchers.TypeSafeMatcher; @@ -33,18 +32,18 @@ */ public class JSONCompareTest { @Test - public void succeedsWithEmptyArrays() throws JSONException { + public void succeedsWithEmptyArrays() { assertTrue(compareJSON("[]", "[]", LENIENT).passed()); } @Test - public void reportsArraysOfUnequalLength() throws JSONException { + public void reportsArraysOfUnequalLength() { JSONCompareResult result = compareJSON("[4]", "[]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]: Expected 1 values but got 0"))); } @Test - public void reportsArrayMissingExpectedElement() throws JSONException { + public void reportsArrayMissingExpectedElement() { JSONCompareResult result = compareJSON("[4]", "[7]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]\nExpected: 4\n but none found\n ; []\nUnexpected: 7\n"))); assertEquals(result.getFieldMissing().size(), 1); @@ -52,65 +51,65 @@ public void reportsArrayMissingExpectedElement() throws JSONException { } @Test - public void reportsMismatchedFieldValues() throws JSONException { + public void reportsMismatchedFieldValues() { JSONCompareResult result = compareJSON("{\"id\": 3}", "{\"id\": 5}", LENIENT); assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n"))); assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: 5\n"))); } @Test - public void reportsMissingField() throws JSONException { + public void reportsMissingField() { JSONCompareResult result = compareJSON("{\"obj\": {\"id\": 3}}", "{\"obj\": {}}", LENIENT); assertThat(result, failsWithMessage(equalTo("obj\nExpected: id\n but none found\n"))); assertEquals(result.getFieldMissing().size(), 1); } @Test - public void reportsUnexpectedArrayWhenExpectingObject() throws JSONException { + public void reportsUnexpectedArrayWhenExpectingObject() { JSONCompareResult result = compareJSON("{}", "[]", LENIENT); assertThat(result, failsWithMessage(equalTo("\nExpected: a JSON object\n got: a JSON array\n"))); } @Test - public void reportsUnexpectedObjectWhenExpectingArray() throws JSONException { + public void reportsUnexpectedObjectWhenExpectingArray() { JSONCompareResult result = compareJSON("[]", "{}", LENIENT); assertThat(result, failsWithMessage(equalTo("\nExpected: a JSON array\n got: a JSON object\n"))); } @Test - public void reportsUnexpectedNull() throws JSONException { + public void reportsUnexpectedNull() { JSONCompareResult result = compareJSON("{\"id\": 3}", "{\"id\": null}", LENIENT); assertThat(result, failsWithMessage(equalTo("id\nExpected: 3\n got: null\n"))); } @Test - public void reportsUnexpectedNonNull() throws JSONException { + public void reportsUnexpectedNonNull() { JSONCompareResult result = compareJSON("{\"id\": null}", "{\"id\": \"abc\"}", LENIENT); assertThat(result, failsWithMessage(equalTo("id\nExpected: null\n got: abc\n"))); } @Test - public void reportsUnexpectedFieldInNonExtensibleMode() throws JSONException { + public void reportsUnexpectedFieldInNonExtensibleMode() { JSONCompareResult result = compareJSON("{\"obj\": {}}", "{\"obj\": {\"id\": 3}}", NON_EXTENSIBLE); assertThat(result, failsWithMessage(equalTo("obj\nUnexpected: id\n"))); assertEquals(result.getFieldUnexpected().size(), 1); } @Test - public void reportsMismatchedTypes() throws JSONException { + public void reportsMismatchedTypes() { JSONCompareResult result = compareJSON("{\"arr\":[]}", "{\"arr\":{}}", LENIENT); assertThat(result, failsWithMessage(equalTo("arr\nExpected: a JSON array\n got: a JSON object\n"))); } @Test - public void reportsWrongSimpleValueCountInUnorderedArray() throws JSONException { + public void reportsWrongSimpleValueCountInUnorderedArray() { JSONCompareResult result = compareJSON("[5, 5]", "[5, 7]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]: Expected 2 occurrence(s) of 5 but got 1 occurrence(s) ; []\nUnexpected: 7\n"))); assertEquals(result.getFieldUnexpected().size(), 1); } @Test - public void reportsMissingJSONObjectWithUniqueKeyInUnorderedArray() throws JSONException { + public void reportsMissingJSONObjectWithUniqueKeyInUnorderedArray() { JSONCompareResult result = compareJSON("[{\"id\" : 3}]", "[{\"id\" : 5}]", LENIENT); assertThat(result, failsWithMessage(equalTo("[id=3]\nExpected: a JSON object\n but none found\n ; " + "[id=5]\nUnexpected: a JSON object\n"))); @@ -119,42 +118,42 @@ public void reportsMissingJSONObjectWithUniqueKeyInUnorderedArray() throws JSONE } @Test - public void reportsUnmatchedJSONObjectInUnorderedArray() throws JSONException { + public void reportsUnmatchedJSONObjectInUnorderedArray() { JSONCompareResult result = compareJSON("[{\"address\" : {\"street\" : \"Acacia Avenue\"}}]", "[{\"age\" : 23}]", LENIENT); assertThat(result, failsWithMessage(equalTo("[0] Could not find match for element {\"address\":{\"street\":\"Acacia Avenue\"}}"))); } @Test - public void succeedsWithNestedJSONObjectsInUnorderedArray() throws JSONException { + public void succeedsWithNestedJSONObjectsInUnorderedArray() { assertTrue(compareJSON("[{\"address\" : {\"street\" : \"Acacia Avenue\"}}, 5]", "[5, {\"address\" : {\"street\" : \"Acacia Avenue\"}}]", LENIENT).passed()); } @Test - public void succeedsWithJSONObjectsWithNonUniqueKeyInUnorderedArray() throws JSONException { + public void succeedsWithJSONObjectsWithNonUniqueKeyInUnorderedArray() { String jsonDocument = "[{\"age\" : 43}, {\"age\" : 43}]"; assertTrue(compareJSON(jsonDocument, jsonDocument, LENIENT).passed()); } @Test - public void succeedsWithSomeNestedJSONObjectsInUnorderedArray() throws JSONException { + public void succeedsWithSomeNestedJSONObjectsInUnorderedArray() { String jsonDocument = "[{\"age\" : 43}, {\"age\" : {\"years\" : 43}}]"; assertTrue(compareJSON(jsonDocument, jsonDocument, LENIENT).passed()); } @Test - public void reportsUnmatchesIntegerValueInUnorderedArrayContainingJSONObject() throws JSONException { + public void reportsUnmatchesIntegerValueInUnorderedArrayContainingJSONObject() { JSONCompareResult result = compareJSON("[{\"address\" : {\"street\" : \"Acacia Avenue\"}}, 5]", "[{\"address\" : {\"street\" : \"Acacia Avenue\"}}, 2]", LENIENT); assertThat(result, failsWithMessage(equalTo("[1] Could not find match for element 5"))); } @Test - public void reportsUnmatchedJSONArrayWhereOnlyExpectedContainsJSONObjectWithUniqueKey() throws JSONException { + public void reportsUnmatchedJSONArrayWhereOnlyExpectedContainsJSONObjectWithUniqueKey() { JSONCompareResult result = compareJSON("[{\"id\": 3}]", "[{}]", LENIENT); assertThat(result, failsWithMessage(equalTo("[0] Could not find match for element {\"id\":3}"))); } @Test - public void reportsUnmatchedJSONArrayWhereExpectedContainsJSONObjectWithUniqueKeyButActualContainsElementOfOtherType() throws JSONException { + public void reportsUnmatchedJSONArrayWhereExpectedContainsJSONObjectWithUniqueKeyButActualContainsElementOfOtherType() { JSONCompareResult result = compareJSON("[{\"id\": 3}]", "[5]", LENIENT); assertThat(result, failsWithMessage(equalTo("[0] Could not find match for element {\"id\":3}"))); } diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java index 5f4c36ca..53546166 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCustomComparatorTest.java @@ -14,7 +14,6 @@ package org.skyscreamer.jsonassert; -import org.json.JSONException; import org.junit.Test; import org.skyscreamer.jsonassert.comparator.CustomComparator; import org.skyscreamer.jsonassert.comparator.JSONComparator; @@ -128,7 +127,7 @@ public boolean equal(Object o1, Object o2) { }; @Test - public void whenPathMatchesInCustomizationThenCallCustomMatcher() throws JSONException { + public void whenPathMatchesInCustomizationThenCallCustomMatcher() { JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new Customization("first", comparator)); JSONCompareResult result = compareJSON(expected, actual, jsonCmp); assertTrue(result.getMessage(), result.passed()); @@ -136,7 +135,7 @@ public void whenPathMatchesInCustomizationThenCallCustomMatcher() throws JSONExc } @Test - public void whenDeepPathMatchesCallCustomMatcher() throws JSONException { + public void whenDeepPathMatchesCallCustomMatcher() { JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new Customization("outer.inner.value", comparator)); JSONCompareResult result = compareJSON(deepExpected, deepActual, jsonCmp); assertTrue(result.getMessage(), result.passed()); @@ -144,7 +143,7 @@ public void whenDeepPathMatchesCallCustomMatcher() throws JSONException { } @Test - public void whenSimpleWildcardPathMatchesCallCustomMatcher() throws JSONException { + public void whenSimpleWildcardPathMatchesCallCustomMatcher() { JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new Customization("foo.*.baz", comparator)); JSONCompareResult result = compareJSON(simpleWildcardExpected, simpleWildcardActual, jsonCmp); assertTrue(result.getMessage(), result.passed()); @@ -152,7 +151,7 @@ public void whenSimpleWildcardPathMatchesCallCustomMatcher() throws JSONExceptio } @Test - public void whenDeepWildcardPathMatchesCallCustomMatcher() throws JSONException { + public void whenDeepWildcardPathMatchesCallCustomMatcher() { JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new Customization("root.**.baz", comparator)); JSONCompareResult result = compareJSON(deepWildcardExpected, deepWildcardActual, jsonCmp); assertTrue(result.getMessage(), result.passed()); @@ -160,7 +159,7 @@ public void whenDeepWildcardPathMatchesCallCustomMatcher() throws JSONException } @Test - public void whenRootDeepWildcardPathMatchesCallCustomMatcher() throws JSONException { + public void whenRootDeepWildcardPathMatchesCallCustomMatcher() { JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new Customization("**.baz", comparator)); JSONCompareResult result = compareJSON(rootDeepWildcardExpected, rootDeepWildcardActual, jsonCmp); assertTrue(result.getMessage(), result.passed()); diff --git a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java index 0e591da8..18539bc0 100644 --- a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java @@ -16,10 +16,7 @@ import org.junit.Assert; -import org.json.JSONException; import org.junit.Test; -import org.skyscreamer.jsonassert.Customization; -import org.skyscreamer.jsonassert.JSONCompareMode; import org.skyscreamer.jsonassert.comparator.CustomComparator; /** @@ -34,52 +31,52 @@ public class RegularExpressionValueMatcherTest { private static final String CONSTANT_URI_REGEX_EXPECTED_JSON = "{d:{results:[{__metadata:{uri:X}}]}}"; private void doTest(String jsonPath, String regex, String expectedJSON, - String actualJSON) throws JSONException { + String actualJSON) { JSONAssert.assertEquals(expectedJSON, actualJSON, new CustomComparator( JSONCompareMode.STRICT_ORDER, new Customization(jsonPath, new RegularExpressionValueMatcher(regex)))); } @Test - public void constantRegexWithSimplePathMatchsStringAttribute() throws JSONException { + public void constantRegexWithSimplePathMatchsStringAttribute() { doTest("a", "v.", "{a:x}", "{a:v1}"); } @Test - public void constantRegexWithThreeLevelPathMatchsStringAttribute() throws JSONException { + public void constantRegexWithThreeLevelPathMatchsStringAttribute() { doTest("a.b.c", ".*Is.*", "{a:{b:{c:x}}}", "{a:{b:{c:thisIsAString}}}"); } @Test - public void dynamicRegexWithSimplePathMatchsStringAttribute() throws JSONException { + public void dynamicRegexWithSimplePathMatchsStringAttribute() { doTest("a", null, "{a:\"v.\"}", "{a:v1}"); } @Test - public void dynamicRegexWithThreeLevelPathMatchsStringAttribute() throws JSONException { + public void dynamicRegexWithThreeLevelPathMatchsStringAttribute() { doTest("a.b.c", null, "{a:{b:{c:\".*Is.*\"}}}", "{a:{b:{c:thisIsAString}}}"); } @Test - public void constantRegexMatchesStringAttributeInsideArray() throws JSONException { + public void constantRegexMatchesStringAttributeInsideArray() { doTest(ARRAY_ELEMENT_PREFIX, "http://localhost:80/Person\\('\\d+'\\)", CONSTANT_URI_REGEX_EXPECTED_JSON, JSON_STRING_WITH_ARRAY); } @Test - public void dynamicRegexMatchesStringAttributeInsideArray() throws JSONException { + public void dynamicRegexMatchesStringAttributeInsideArray() { doTest(ARRAY_ELEMENT_PREFIX, null, "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person\\\\('\\\\d+'\\\\)\"}}]}}", JSON_STRING_WITH_ARRAY); } @Test - public void dynamicRegexMatchesStringAttributeInsideArrayWithNoArgConstructor() throws JSONException { + public void dynamicRegexMatchesStringAttributeInsideArrayWithNoArgConstructor() { JSONAssert.assertEquals("{d:{results:[{__metadata:{uri:\"http://localhost:80/Person\\\\('\\\\d+'\\\\)\"}}]}}", JSON_STRING_WITH_ARRAY, new CustomComparator( JSONCompareMode.STRICT_ORDER, new Customization(ARRAY_ELEMENT_PREFIX, new RegularExpressionValueMatcher()))); } @Test - public void failsWhenDynamicRegexInvalid() throws JSONException { + public void failsWhenDynamicRegexInvalid() { try { doTest(ARRAY_ELEMENT_PREFIX, null, "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person('\\\\d+'\\\\)\"}}]}}", JSON_STRING_WITH_ARRAY); } @@ -89,7 +86,7 @@ public void failsWhenDynamicRegexInvalid() throws JSONException { } @Test - public void failsWhenDynamicRegexDoesNotMatchStringAttributeInsideArray() throws JSONException { + public void failsWhenDynamicRegexDoesNotMatchStringAttributeInsideArray() { try { doTest(ARRAY_ELEMENT_PREFIX, null, "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person\\\\('\\\\w+'\\\\)\"}}]}}", JSON_STRING_WITH_ARRAY); } @@ -99,7 +96,7 @@ public void failsWhenDynamicRegexDoesNotMatchStringAttributeInsideArray() throws } @Test - public void failsWhenConstantRegexInvalid() throws JSONException { + public void failsWhenConstantRegexInvalid() { try { doTest(ARRAY_ELEMENT_PREFIX, "http://localhost:80/Person\\\\['\\\\d+'\\\\)", CONSTANT_URI_REGEX_EXPECTED_JSON, JSON_STRING_WITH_ARRAY); } @@ -109,7 +106,7 @@ public void failsWhenConstantRegexInvalid() throws JSONException { } @Test - public void failsWhenConstantRegexDoesNotMatchStringAttributeInsideArray() throws JSONException { + public void failsWhenConstantRegexDoesNotMatchStringAttributeInsideArray() { try { doTest(ARRAY_ELEMENT_PREFIX, "http://localhost:80/Person\\\\('\\\\w+'\\\\)", CONSTANT_URI_REGEX_EXPECTED_JSON, JSON_STRING_WITH_ARRAY); } diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java index c949e8b8..7af97ee5 100644 --- a/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java @@ -19,7 +19,6 @@ import java.text.MessageFormat; -import org.json.JSONException; import org.junit.Test; import org.skyscreamer.jsonassert.JSONAssert; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -33,12 +32,12 @@ public class ArraySizeComparatorTest { private static final String twoElementArray = "{a:[b,c]}"; - private void doTest(String expectedJSON, String actualJSON) throws JSONException + private void doTest(String expectedJSON, String actualJSON) { JSONAssert.assertEquals(expectedJSON, actualJSON, new ArraySizeComparator(JSONCompareMode.STRICT_ORDER)); } - private void doFailingMatchTest(String expectedJSON, String actualJSON, String expectedMessagePattern) throws JSONException { + private void doFailingMatchTest(String expectedJSON, String actualJSON, String expectedMessagePattern) { try { doTest(expectedJSON, actualJSON); } @@ -51,77 +50,77 @@ private void doFailingMatchTest(String expectedJSON, String actualJSON, String e } @Test - public void succeedsWhenExactSizeExpected() throws JSONException { + public void succeedsWhenExactSizeExpected() { doTest("{a:[2]}", twoElementArray); } @Test - public void succeedsWhenSizeWithinExpectedRange() throws JSONException { + public void succeedsWhenSizeWithinExpectedRange() { doTest("{a:[1,3]}", twoElementArray); } @Test - public void succeedsWhenSizeIsMinimumOfExpectedRange() throws JSONException { + public void succeedsWhenSizeIsMinimumOfExpectedRange() { doTest("{a:[2,4]}", twoElementArray); } @Test - public void succeedsWhenSizeIsMaximumOfExpectedRange() throws JSONException { + public void succeedsWhenSizeIsMaximumOfExpectedRange() { doTest("{a:[1,2]}", twoElementArray); } @Test - public void failsWhenExpectedArrayTooShort() throws JSONException { + public void failsWhenExpectedArrayTooShort() { doFailingMatchTest("{a:[]}", twoElementArray, "a\\[\\]: invalid expectation: expected array should contain either 1 or 2 elements but contains 0 elements"); } @Test - public void failsWhenExpectedArrayTooLong() throws JSONException { + public void failsWhenExpectedArrayTooLong() { doFailingMatchTest("{a:[1,2,3]}", twoElementArray, "a\\[\\]: invalid expectation: expected array should contain either 1 or 2 elements but contains 3 elements"); } @Test - public void failsWhenExpectedNotAllSimpleTypes() throws JSONException { + public void failsWhenExpectedNotAllSimpleTypes() { doFailingMatchTest("{a:[{y:1},2]}", twoElementArray, "a\\[\\]: invalid expectation: minimum expected array size '\\{\"y\":1\\}' not a number"); } @Test - public void failsWhenExpectedMinimumTooSmall() throws JSONException { + public void failsWhenExpectedMinimumTooSmall() { doFailingMatchTest("{a:[-1,6]}", twoElementArray, "a\\[\\]: invalid expectation: minimum expected array size '-1' negative"); } @Test - public void failsWhenExpectedMaximumTooSmall() throws JSONException { + public void failsWhenExpectedMaximumTooSmall() { doFailingMatchTest("{a:[8,6]}", twoElementArray, "a\\[\\]: invalid expectation: maximum expected array size '6' less than minimum expected array size '8'"); } @Test - public void failsWhenExpectedArraySizeNotANumber() throws JSONException { + public void failsWhenExpectedArraySizeNotANumber() { doFailingMatchTest("{a:[X]}", twoElementArray, "a\\[\\]: invalid expectation: expected array size 'X' not a number"); } @Test - public void failsWhenFirstExpectedArrayElementNotANumber() throws JSONException { + public void failsWhenFirstExpectedArrayElementNotANumber() { doFailingMatchTest("{a:[MIN,6]}", twoElementArray, "a\\[\\]: invalid expectation: minimum expected array size 'MIN' not a number"); } @Test - public void failsWhenSecondExpectedArrayElementNotANumber() throws JSONException { + public void failsWhenSecondExpectedArrayElementNotANumber() { doFailingMatchTest("{a:[8,MAX]}", twoElementArray, "a\\[\\]: invalid expectation: maximum expected array size 'MAX' not a number"); } @Test - public void failsWhenActualArrayTooShort() throws JSONException { + public void failsWhenActualArrayTooShort() { doFailingMatchTest("{a:[3]}", twoElementArray, "a\\[\\]\\s*Expected:\\s*array size of 3 elements\\s*got:\\s*2 elements\\s*"); } @Test - public void failsWhenActualArrayLongerThanExpectedLength() throws JSONException { + public void failsWhenActualArrayLongerThanExpectedLength() { doFailingMatchTest("{a:[1]}", twoElementArray, "a\\[\\]\\s*Expected:\\s*array size of 1 elements\\s*got:\\s*2 elements\\s*"); } @Test - public void failsWhenActualArrayLongerThanMaxOfExpectedRange() throws JSONException { + public void failsWhenActualArrayLongerThanMaxOfExpectedRange() { doFailingMatchTest("{a:[0,1]}", twoElementArray, "a\\[\\]\\s*Expected:\\s*array size of 0 to 1 elements\\s*got:\\s*2 elements\\s*"); } @@ -130,12 +129,12 @@ public void failsWhenActualArrayLongerThanMaxOfExpectedRange() throws JSONExcept */ @Test - public void succeedsWhenActualArrayContainsExactly3Elements() throws JSONException { + public void succeedsWhenActualArrayContainsExactly3Elements() { JSONAssert.assertEquals("{a:[3]}", "{a:[7, 8, 9]}", new ArraySizeComparator(JSONCompareMode.LENIENT)); } @Test - public void succeedsWhenActualArrayContainsBetween2And6Elements() throws JSONException { + public void succeedsWhenActualArrayContainsBetween2And6Elements() { JSONAssert.assertEquals("{a:[2,6]}", "{a:[7, 8, 9]}", new ArraySizeComparator(JSONCompareMode.LENIENT)); } diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java index 651e6a87..b48ffb59 100644 --- a/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/comparator/CustomComparatorTest.java @@ -16,7 +16,6 @@ import junit.framework.Assert; import org.json.JSONArray; -import org.json.JSONException; import org.junit.Test; import org.skyscreamer.jsonassert.JSONCompare; import org.skyscreamer.jsonassert.JSONCompareMode; @@ -34,7 +33,7 @@ public ArrayOfJsonObjectsComparator(JSONCompareMode mode) { } @Override - public void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result) throws JSONException { + public void compareJSONArray(String prefix, JSONArray expected, JSONArray actual, JSONCompareResult result) { compareJSONArrayOfJsonObjects(prefix, expected, actual, result); } } From 4e175c3b8e99f235b13f8353b7474ae64db84b2d Mon Sep 17 00:00:00 2001 From: Michael Edgar Date: Fri, 26 Jul 2024 10:06:25 -0400 Subject: [PATCH 72/84] Avoid NullPointerException describing null value (#172) Signed-off-by: Michael Edgar --- .../jsonassert/JSONCompareResult.java | 2 +- .../comparator/DefaultComparator.java | 5 ++-- .../jsonassert/JSONCompareTest.java | 27 +++++++++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java index 28406fbe..55672099 100644 --- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java +++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java @@ -245,7 +245,7 @@ private static String describe(Object value) { } else if (value instanceof JSONObject) { return "a JSON object"; } else { - return value.toString(); + return String.valueOf(value); } } diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java index 7d1bcc16..1e8efc01 100644 --- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java +++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java @@ -50,10 +50,9 @@ public void compareValues(String prefix, Object expectedValue, Object actualValu if (expectedValue == actualValue) { return; } - if ((expectedValue == null && actualValue != null) || (expectedValue != null && actualValue == null)) { + if (expectedValue == null || actualValue == null) { result.fail(prefix, expectedValue, actualValue); - } - if (areNumbers(expectedValue, actualValue)) { + } else if (areNumbers(expectedValue, actualValue)) { if (areNotSameDoubles(expectedValue, actualValue)) { result.fail(prefix, expectedValue, actualValue); } diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java index 17c20972..8cb05043 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java @@ -21,6 +21,7 @@ import static org.skyscreamer.jsonassert.JSONCompare.compareJSON; import static org.skyscreamer.jsonassert.JSONCompareMode.LENIENT; import static org.skyscreamer.jsonassert.JSONCompareMode.NON_EXTENSIBLE; +import static org.skyscreamer.jsonassert.JSONCompareMode.STRICT; import org.hamcrest.Description; import org.hamcrest.Matcher; @@ -158,6 +159,32 @@ public void reportsUnmatchedJSONArrayWhereExpectedContainsJSONObjectWithUniqueKe assertThat(result, failsWithMessage(equalTo("[0] Could not find match for element {\"id\":3}"))); } + @Test + public void reportsUnmatchedJSONArrayWhereExpectedContainsNonnullIntegerButActualContainsNullElement() throws JSONException { + JSONCompareResult result = compareJSON("[ 3 ]", "[ null ]", LENIENT); + assertThat(result, failsWithMessage(equalTo("[]\nExpected: 3\n but none found\n ; " + + "[]\nUnexpected: null\n"))); + } + + @Test + public void reportsUnmatchedJSONArrayWhereExpectedContainsNullElementButActualContainsNonnullInteger() throws JSONException { + JSONCompareResult result = compareJSON("[ null ]", "[ 3 ]", LENIENT); + assertThat(result, failsWithMessage(equalTo("[]\nExpected: null\n but none found\n ; " + + "[]\nUnexpected: 3\n"))); + } + + @Test + public void reportsStrictUnmatchedJSONArrayWhereExpectedContainsNonnullIntegerButActualContainsNullElement() throws JSONException { + JSONCompareResult result = compareJSON("[ 3 ]", "[ null ]", STRICT); + assertThat(result, failsWithMessage(equalTo("[0]\nExpected: 3\n got: null\n"))); + } + + @Test + public void reportsStrictUnmatchedJSONArrayWhereExpectedContainsNullButActualContainsNonnullInteger() throws JSONException { + JSONCompareResult result = compareJSON("[ null ]", "[ 3 ]", STRICT); + assertThat(result, failsWithMessage(equalTo("[0]\nExpected: null\n got: 3\n"))); + } + private Matcher failsWithMessage(final Matcher expectedMessage) { return new TypeSafeMatcher() { @Override From 8e75370663d731622681749e64a492ec8a7a3503 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 26 Jul 2024 10:12:38 -0400 Subject: [PATCH 73/84] Fix new tests to support v2 (#195) Updated new tests for v2 by removing "throws JSONException" --- .../java/org/skyscreamer/jsonassert/JSONCompareTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java index 8cb05043..3bcb7377 100644 --- a/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java +++ b/src/test/java/org/skyscreamer/jsonassert/JSONCompareTest.java @@ -160,27 +160,27 @@ public void reportsUnmatchedJSONArrayWhereExpectedContainsJSONObjectWithUniqueKe } @Test - public void reportsUnmatchedJSONArrayWhereExpectedContainsNonnullIntegerButActualContainsNullElement() throws JSONException { + public void reportsUnmatchedJSONArrayWhereExpectedContainsNonnullIntegerButActualContainsNullElement() { JSONCompareResult result = compareJSON("[ 3 ]", "[ null ]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]\nExpected: 3\n but none found\n ; " + "[]\nUnexpected: null\n"))); } @Test - public void reportsUnmatchedJSONArrayWhereExpectedContainsNullElementButActualContainsNonnullInteger() throws JSONException { + public void reportsUnmatchedJSONArrayWhereExpectedContainsNullElementButActualContainsNonnullInteger() { JSONCompareResult result = compareJSON("[ null ]", "[ 3 ]", LENIENT); assertThat(result, failsWithMessage(equalTo("[]\nExpected: null\n but none found\n ; " + "[]\nUnexpected: 3\n"))); } @Test - public void reportsStrictUnmatchedJSONArrayWhereExpectedContainsNonnullIntegerButActualContainsNullElement() throws JSONException { + public void reportsStrictUnmatchedJSONArrayWhereExpectedContainsNonnullIntegerButActualContainsNullElement() { JSONCompareResult result = compareJSON("[ 3 ]", "[ null ]", STRICT); assertThat(result, failsWithMessage(equalTo("[0]\nExpected: 3\n got: null\n"))); } @Test - public void reportsStrictUnmatchedJSONArrayWhereExpectedContainsNullButActualContainsNonnullInteger() throws JSONException { + public void reportsStrictUnmatchedJSONArrayWhereExpectedContainsNullButActualContainsNonnullInteger() { JSONCompareResult result = compareJSON("[ null ]", "[ 3 ]", STRICT); assertThat(result, failsWithMessage(equalTo("[0]\nExpected: null\n got: 3\n"))); } From 77ca536ee23e187d437c3b1a56667534bb48a831 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 26 Jul 2024 14:46:50 -0400 Subject: [PATCH 74/84] Create auto-deploy static.yml --- .github/workflows/static.yml | 43 ++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 .github/workflows/static.yml diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml new file mode 100644 index 00000000..1a149028 --- /dev/null +++ b/.github/workflows/static.yml @@ -0,0 +1,43 @@ +# Simple workflow for deploying static content to GitHub Pages +name: Deploy static content to Pages + +on: + # Runs on pushes targeting the default branch + push: + branches: ["master"] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + # Single deploy job since we're just deploying + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + # Upload entire repository + path: './src/site' + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 From 15a83f25db28501f88923eb58b2239a101bb13be Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 26 Jul 2024 15:09:16 -0400 Subject: [PATCH 75/84] Update site deploy static.yml --- .github/workflows/static.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 1a149028..d6de2c70 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -37,7 +37,7 @@ jobs: uses: actions/upload-pages-artifact@v3 with: # Upload entire repository - path: './src/site' + path: './src/site/resources' - name: Deploy to GitHub Pages id: deployment uses: actions/deploy-pages@v4 From 0be80f35daa942d8a7d5063eec0502404d7d5474 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 26 Jul 2024 15:53:52 -0400 Subject: [PATCH 76/84] Add javadoc creation to Github Actions --- .github/workflows/static.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index d6de2c70..0dbb95e3 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -33,6 +33,13 @@ jobs: uses: actions/checkout@v4 - name: Setup Pages uses: actions/configure-pages@v5 + - name: Deploy JavaDoc 🚀 + uses: MathieuSoysal/Javadoc-publisher.yml@v2.5.0 + with: + java-version: 8 + deploy-mode: artifact + javadoc-source-folder: ./src/site/resources/apidocs + project: maven - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: From 67b238795d7aea63780b64b657cf95b737760bae Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 26 Jul 2024 15:58:24 -0400 Subject: [PATCH 77/84] Update to javadoc autodeploy --- .github/workflows/static.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 0dbb95e3..9179c1c0 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -37,9 +37,10 @@ jobs: uses: MathieuSoysal/Javadoc-publisher.yml@v2.5.0 with: java-version: 8 - deploy-mode: artifact javadoc-source-folder: ./src/site/resources/apidocs project: maven + without-deploy: true + without-checkout: true - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: From b4e2f5f407c09b833607e184a34394f28aac97cc Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 26 Jul 2024 16:12:02 -0400 Subject: [PATCH 78/84] Github Actions: replace javadoc action with maven command --- .github/workflows/static.yml | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml index 9179c1c0..bf06169d 100644 --- a/.github/workflows/static.yml +++ b/.github/workflows/static.yml @@ -33,14 +33,13 @@ jobs: uses: actions/checkout@v4 - name: Setup Pages uses: actions/configure-pages@v5 - - name: Deploy JavaDoc 🚀 - uses: MathieuSoysal/Javadoc-publisher.yml@v2.5.0 + - uses: actions/setup-java@v4 with: - java-version: 8 - javadoc-source-folder: ./src/site/resources/apidocs - project: maven - without-deploy: true - without-checkout: true + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Run the Maven javadoc command + run: mvn javadoc:aggregate -DreportOutputDirectory=src/site/resources/apidocs - name: Upload artifact uses: actions/upload-pages-artifact@v3 with: From ac0880cf2aa8901e0542763510179390540c0ae4 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Fri, 26 Jul 2024 16:31:43 -0400 Subject: [PATCH 79/84] Remove wagon from pom.xml (Using GH actions now) (#196) Revert recommended version to 1.5.3 in web pages Co-authored-by: Carter Page --- pom.xml | 5 ----- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index cc1299a1..4188fbd2 100644 --- a/pom.xml +++ b/pom.xml @@ -106,11 +106,6 @@ maven-scm-manager-plexus 1.12.2 - - org.kathrynhuxtable.maven.wagon - wagon-gitsite - 0.3.1 - diff --git a/src/site/resources/index.html b/src/site/resources/index.html index 97f11932..2bca2d18 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

    Introduction

  • JUnit
  • -


    The current version of JSONassert is 2.0.0-SNAPSHOT

    +


    The current version of JSONassert is 1.5.3

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index a7f45c50..00b36f86 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>2.0.0-SNAPSHOT</version>
    +   <version>1.5.3</version>
    </dependency>
    From c4bcc6ac9af542d6202b1d3715b897f73e0c4bb4 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sat, 27 Jul 2024 15:20:44 -0400 Subject: [PATCH 80/84] Some cleanup (#198) * Cleanup pom. * Give Github Actions file a better name. --- .../{static.yml => deploy-website.yml} | 0 pom.xml | 28 +------------------ 2 files changed, 1 insertion(+), 27 deletions(-) rename .github/workflows/{static.yml => deploy-website.yml} (100%) diff --git a/.github/workflows/static.yml b/.github/workflows/deploy-website.yml similarity index 100% rename from .github/workflows/static.yml rename to .github/workflows/deploy-website.yml diff --git a/pom.xml b/pom.xml index 4188fbd2..d5c74c1d 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.skyscreamer jsonassert - 2.0.0-SNAPSHOT + 2.0-rc1 jar JSONassert @@ -22,11 +22,6 @@ repo - - scm:git:git@github.com:skyscreamer/JSONassert.git - scm:git:git@github.com:skyscreamer/JSONassert.git - git@github.com:skyscreamer/JSONassert.git - carterpage @@ -36,11 +31,6 @@ hertzsprung James Shaw - - - cepage - Corby Page - corby@skyscreamer.org @@ -72,10 +62,6 @@ maven-compiler-plugin 3.11.0 - - org.apache.maven.plugins - maven-site-plugin - org.sonatype.plugins nexus-staging-maven-plugin @@ -95,18 +81,6 @@ - - - org.apache.maven.scm - maven-scm-provider-gitexe - 1.12.2 - - - org.apache.maven.scm - maven-scm-manager-plexus - 1.12.2 - - From ee6c816117f8a4b09e7ad02b8eec8ff0f2c58323 Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 28 Jul 2024 09:37:12 -0400 Subject: [PATCH 81/84] Make deploy-website.yml manual only --- .github/workflows/deploy-website.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index bf06169d..fb527d76 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -2,9 +2,9 @@ name: Deploy static content to Pages on: - # Runs on pushes targeting the default branch - push: - branches: ["master"] + # Runs on pushes targeting the default branch - disabled, manual only + #push: + # branches: ["master"] # Allows you to run this workflow manually from the Actions tab workflow_dispatch: From d7689bf8c412f98c3d9266a37ddd72f18ade545e Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 28 Jul 2024 13:52:17 -0400 Subject: [PATCH 82/84] Preparing for 2.0-rc1 release --- CHANGELOG.md | 8 ++++++-- src/site/resources/index.html | 2 +- src/site/resources/quickstart.html | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0240ee0e..1b33ee64 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,13 @@ Changelog ========= -Version 2.0.0 - TBD +Version 2.0-rc1 - 7/28/2024 ------------------- - - TODO - placeholder + - Release candidate + - ** Switches JSON implementation to use org.json:json:20240303 ** + - Deployment still built with Java version 8 to maximize compatibility + - Cannot insert null directly into JSONArray without casting. Recommend to use JSONObject.Null + - JSONException is now a RuntimeException. Is not defined as thrown in method signatures anynmore. Version 1.5.3 - 6/28/2024 ------------------------- diff --git a/src/site/resources/index.html b/src/site/resources/index.html index 2bca2d18..41f2c5ae 100644 --- a/src/site/resources/index.html +++ b/src/site/resources/index.html @@ -51,7 +51,7 @@

    Introduction

  • JUnit
  • -


    The current version of JSONassert is 1.5.3

    +


    The current version of JSONassert is 2.0-rc1

    Examples

    diff --git a/src/site/resources/quickstart.html b/src/site/resources/quickstart.html index 00b36f86..371e3575 100644 --- a/src/site/resources/quickstart.html +++ b/src/site/resources/quickstart.html @@ -49,7 +49,7 @@

    Quick Start

    <dependency>
      <groupId>org.skyscreamer</groupId>
      <artifactId>jsonassert</artifactId>
    -   <version>1.5.3</version>
    +   <version>2.0-rc1</version>
    </dependency>
    From c6c838bec639f90a65d541d049a434708fee1eee Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 28 Jul 2024 13:58:36 -0400 Subject: [PATCH 83/84] Replacing SCM tags (required by sonatype) --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index d5c74c1d..86738534 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,11 @@ repo + + scm:git:git@github.com:skyscreamer/JSONassert.git + scm:git:git@github.com:skyscreamer/JSONassert.git + git@github.com:skyscreamer/JSONassert.git + carterpage From e81c16c59ce0860f97a65d871589ab2337370c4b Mon Sep 17 00:00:00 2001 From: Carter Page Date: Sun, 28 Jul 2024 14:03:56 -0400 Subject: [PATCH 84/84] Update README.md to reference v2.0-rc1 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d6b5a932..871b1e19 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o org.skyscreamer jsonassert - 2.0.0-SNAPSHOT + 2.0-rc1 test
    + * Behavior of JSONCompareMode + *
     ExtensibleStrict Ordering
    STRICTnoyes
    LENIENTyesno