This library uses org.json. It has fewer dependencies than other JSON libraries (like net.sf.json),
+ *
This library uses org.json. It has fewer dependencies than other JSON libraries (like net.sf.json),
* making JSONassert more portable.
*
*
There are two known issues when dealing with non-strict comparisons:
@@ -31,7 +31,7 @@
*
Unless the order is strict, checking cannot handle arrays of arrays (e.g. [[1,2],[3,4]])
*
*
You do not have to worry about encountering a false positive or false negative in these two edge cases.
- * JSONassert will identify the conditions and throw a descriptive {@link IllegalArgumentException}. These
+ * JSONassert will identify the conditions and throw a descriptive {@link IllegalArgumentException}. These
* cases will be fixed in future versions.
*
*/
@@ -39,7 +39,7 @@ public class JSONAssert {
private JSONAssert() {}
/**
- * Asserts that the JSONObject provided matches the expected string. If it isn't it throws an
+ * Asserts that the JSONObject provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -53,7 +53,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
+ * Asserts that the JSONObject provided does not match the expected string. If it is it throws an
* {@link AssertionError}.
*
* @see #assertEquals(String JSONObject, boolean)
@@ -69,7 +69,7 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, boolea
}
/**
- * Asserts that the JSONObject provided matches the expected string. If it isn't it throws an
+ * Asserts that the JSONObject provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -89,7 +89,7 @@ public static void assertEquals(String expectedStr, JSONObject actual, JSONCompa
}
/**
- * Asserts that the JSONObject provided does not match the expected string. If it is it throws an
+ * Asserts that the JSONObject provided does not match the expected string. If it is it throws an
* {@link AssertionError}.
*
* @see #assertEquals(String, JSONObject, JSONCompareMode)
@@ -111,7 +111,7 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCo
}
/**
- * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
+ * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -125,7 +125,7 @@ public static void assertEquals(String expectedStr, JSONArray actual, boolean st
}
/**
- * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
+ * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -139,7 +139,7 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, boolean
}
/**
- * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
+ * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -159,7 +159,7 @@ public static void assertEquals(String expectedStr, JSONArray actual, JSONCompar
}
/**
- * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
+ * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -179,7 +179,7 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCom
}
/**
- * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
+ * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -193,7 +193,7 @@ public static void assertEquals(String expectedStr, String actualStr, boolean st
}
/**
- * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
+ * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -207,7 +207,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, boolean
}
/**
- * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
+ * Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -224,7 +224,7 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar
}
/**
- * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
+ * Asserts that the JSONArray provided does not match the expected string. If it is it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -241,7 +241,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom
}
/**
- * Asserts that the json string provided matches the expected string. If it isn't it throws an
+ * Asserts that the json string provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -258,7 +258,7 @@ public static void assertEquals(String expectedStr, String actualStr, JSONCompar
}
/**
- * Asserts that the json string provided does not match the expected string. If it is it throws an
+ * Asserts that the json string provided does not match the expected string. If it is it throws an
* {@link AssertionError}.
*
* @param expectedStr Expected JSON string
@@ -275,7 +275,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom
}
/**
- * Asserts that the JSONObject provided matches the expected JSONObject. If it isn't it throws an
+ * Asserts that the JSONObject provided matches the expected JSONObject. If it isn't it throws an
* {@link AssertionError}.
*
* @param expected Expected JSONObject
@@ -289,7 +289,7 @@ public static void assertEquals(JSONObject expected, JSONObject actual, boolean
}
/**
- * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an
+ * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an
* {@link AssertionError}.
*
* @param expected Expected JSONObject
@@ -303,7 +303,7 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, boole
}
/**
- * Asserts that the JSONObject provided matches the expected JSONObject. If it isn't it throws an
+ * Asserts that the JSONObject provided matches the expected JSONObject. If it isn't it throws an
* {@link AssertionError}.
*
* @param expected Expected JSONObject
@@ -321,7 +321,7 @@ public static void assertEquals(JSONObject expected, JSONObject actual, JSONComp
}
/**
- * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an
+ * Asserts that the JSONObject provided does not match the expected JSONObject. If it is it throws an
* {@link AssertionError}.
*
* @param expected Expected JSONObject
@@ -339,7 +339,7 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONC
}
/**
- * Asserts that the JSONArray provided matches the expected JSONArray. If it isn't it throws an
+ * Asserts that the JSONArray provided matches the expected JSONArray. If it isn't it throws an
* {@link AssertionError}.
*
* @param expected Expected JSONArray
@@ -353,7 +353,7 @@ public static void assertEquals(JSONArray expected, JSONArray actual, boolean st
}
/**
- * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an
+ * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an
* {@link AssertionError}.
*
* @param expected Expected JSONArray
@@ -367,7 +367,7 @@ public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean
}
/**
- * Asserts that the JSONArray provided matches the expected JSONArray. If it isn't it throws an
+ * Asserts that the JSONArray provided matches the expected JSONArray. If it isn't it throws an
* {@link AssertionError}.
*
* @param expected Expected JSONArray
@@ -384,7 +384,7 @@ public static void assertEquals(JSONArray expected, JSONArray actual, JSONCompar
}
/**
- * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an
+ * Asserts that the JSONArray provided does not match the expected JSONArray. If it is it throws an
* {@link AssertionError}.
*
* @param expected Expected JSONArray
diff --git a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java
index 435e0082..906d0cab 100644
--- a/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java
+++ b/src/test/java/org/skyscreamer/jsonassert/JSONAssertTest.java
@@ -44,14 +44,14 @@ public void testReversed() throws JSONException {
@Test // Currently JSONAssert assumes JSONObject.
public void testArray() throws JSONException {
- testPass("[1,2,3]", "[1,2,3]",STRICT);
- testPass("[1,2,3]", "[1,3,2]",LENIENT);
- testFail("[1,2,3]", "[1,3,2]",STRICT);
- testFail("[1,2,3]", "[4,5,6]",LENIENT);
- testPass("[1,2,3]", "[1,2,3]",STRICT_ORDER);
- testPass("[1,2,3]", "[1,3,2]",NON_EXTENSIBLE);
- testFail("[1,2,3]", "[1,3,2]",STRICT_ORDER);
- testFail("[1,2,3]", "[4,5,6]",NON_EXTENSIBLE);
+ testPass("[1,2,3]","[1,2,3]", STRICT);
+ testPass("[1,2,3]","[1,3,2]", LENIENT);
+ testFail("[1,2,3]","[1,3,2]", STRICT);
+ testFail("[1,2,3]","[4,5,6]", LENIENT);
+ testPass("[1,2,3]","[1,2,3]", STRICT_ORDER);
+ testPass("[1,2,3]","[1,3,2]", NON_EXTENSIBLE);
+ testFail("[1,2,3]","[1,3,2]", STRICT_ORDER);
+ testFail("[1,2,3]","[4,5,6]", NON_EXTENSIBLE);
}
@Test
@@ -73,8 +73,8 @@ public void testVeryNested() throws JSONException {
@Test
public void testSimpleArray() throws JSONException {
testPass("{id:1,pets:[\"dog\",\"cat\",\"fish\"]}", // Exact to exact (strict)
- "{id:1,pets:[\"dog\",\"cat\",\"fish\"]}",
- STRICT);
+ "{id:1,pets:[\"dog\",\"cat\",\"fish\"]}",
+ STRICT);
testFail("{id:1,pets:[\"dog\",\"cat\",\"fish\"]}", // Out-of-order fails (strict)
"{id:1,pets:[\"dog\",\"fish\",\"cat\"]}",
STRICT);
From 56123c9cf65abe717fcdbddeaa3108d26427549e Mon Sep 17 00:00:00 2001
From: Stefaan Destoop
Date: Sun, 25 Aug 2013 23:13:37 +0200
Subject: [PATCH 009/121] AssertNotEquals preserve formatting
---
.../skyscreamer/jsonassert/JSONAssert.java | 26 +++++++++----------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java
index 672ae14c..10ce2c1b 100644
--- a/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java
+++ b/src/main/java/org/skyscreamer/jsonassert/JSONAssert.java
@@ -7,14 +7,14 @@
/**
*
A set of assertion methods useful for writing tests methods that return JSON.
- *
+ *
*
There are two modes, strict and non-strict. In most cases, you will probably want
* to set strict to false, since that will make the tests less brittle.
- *
+ *
*
Strict tests require all of the elements requested to be returned, and only those elements
* (ie, the tests are non-extensible). Arrays of elements must be returned in the same
* order as expected. For example, say I'm expecting:
- *
+ *
* {id:123,things['a','b','c']}
*
*
The following would match when doing non-strict checking, but would fail on strict checking:
@@ -71,7 +71,7 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, boolea
/**
* Asserts that the JSONObject provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
- *
+ *
* @param expectedStr Expected JSON string
* @param actual JSONObject to compare
* @param compareMode Specifies which comparison mode to use
@@ -113,7 +113,7 @@ public static void assertNotEquals(String expectedStr, JSONObject actual, JSONCo
/**
* Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
- *
+ *
* @param expectedStr Expected JSON string
* @param actual JSONArray to compare
* @param strict Enables strict checking
@@ -141,7 +141,7 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, boolean
/**
* Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
- *
+ *
* @param expectedStr Expected JSON string
* @param actual JSONArray to compare
* @param compareMode Specifies which comparison mode to use
@@ -181,7 +181,7 @@ public static void assertNotEquals(String expectedStr, JSONArray actual, JSONCom
/**
* Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
- *
+ *
* @param expectedStr Expected JSON string
* @param actualStr String to compare
* @param strict Enables strict checking
@@ -209,7 +209,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, boolean
/**
* Asserts that the JSONArray provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
- *
+ *
* @param expectedStr Expected JSON string
* @param actualStr String to compare
* @param compareMode Specifies which comparison mode to use
@@ -243,7 +243,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom
/**
* Asserts that the json string provided matches the expected string. If it isn't it throws an
* {@link AssertionError}.
- *
+ *
* @param expectedStr Expected JSON string
* @param actualStr String to compare
* @param comparator Comparator
@@ -277,7 +277,7 @@ public static void assertNotEquals(String expectedStr, String actualStr, JSONCom
/**
* 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 strict Enables strict checking
@@ -305,7 +305,7 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, boole
/**
* 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 compareMode Specifies which comparison mode to use
@@ -341,7 +341,7 @@ public static void assertNotEquals(JSONObject expected, JSONObject actual, JSONC
/**
* Asserts that the JSONArray provided matches the expected JSONArray. If it isn't it throws an
* {@link AssertionError}.
- *
+ *
* @param expected Expected JSONArray
* @param actual JSONArray to compare
* @param strict Enables strict checking
@@ -369,7 +369,7 @@ public static void assertNotEquals(JSONArray expected, JSONArray actual, boolean
/**
* Asserts that the JSONArray provided matches the expected JSONArray. If it isn't it throws an
* {@link AssertionError}.
- *
+ *
* @param expected Expected JSONArray
* @param actual JSONArray to compare
* @param compareMode Specifies which comparison mode to use
From cd9dd58c110cd518ae8b62146b04f4313c8a1446 Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Thu, 26 Sep 2013 09:15:33 -0400
Subject: [PATCH 010/121] Update README.md
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index c0f17260..27d59fd3 100644
--- a/README.md
+++ b/README.md
@@ -91,6 +91,7 @@ Who uses JSONassert?
--------------------
+ [yoga](https://github.com/skyscreamer/yoga) - A relational REST framework
+ [hamcrest-json](https://github.com/hertzsprung/hamcrest-json) - Hamcrest matchers for comparing JSON documents
+ + [Mule ESB](http://www.mulesoft.org/)
* * *
From b64ad200b8549cf5c073f4638dcb01baee75224c Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Thu, 24 Oct 2013 06:46:01 -0400
Subject: [PATCH 011/121] Updated versions, CHANGELOG
---
CHANGELOG.md | 8 +++++++-
README.md | 2 +-
src/site/resources/index.html | 2 +-
src/site/resources/quickstart.html | 2 +-
4 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 40611205..c3fe1ae6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,7 +1,13 @@
Changelog
=========
-Version 1.2.0 - 3/17/2012
+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.
+ - Added AssertNotEquals
+
+Version 1.2.0 - 3/17/2013
-------------------------
- Fixed handling comparison of equivalent values across long, int, and double
- Add JSONCompareMode to asserts to allow for more options than strict/not-strict
diff --git a/README.md b/README.md
index 27d59fd3..ba4d63e7 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/downloads)
org.skyscreamerjsonassert
- 1.2.0
+ 1.2.1
Write tests like this:
diff --git a/src/site/resources/index.html b/src/site/resources/index.html
index f84bf34c..14f37e0d 100644
--- a/src/site/resources/index.html
+++ b/src/site/resources/index.html
@@ -51,7 +51,7 @@
From b26c905ab23d13b34b8d545c3caa055eda1982d8 Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Tue, 31 Dec 2013 10:06:06 -0500
Subject: [PATCH 019/121] [maven-release-plugin] prepare release
jsonassert-1.2.2
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 5419140b..130e1c4f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.2-SNAPSHOT
+ 1.2.2jarJSONassert
From 06d38aeafae421e02c7b22650e656389cb35991e Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Tue, 31 Dec 2013 10:06:09 -0500
Subject: [PATCH 020/121] [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 130e1c4f..13afc2ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.2
+ 1.2.3-SNAPSHOTjarJSONassert
From e29c657e90a1e6021cd33b91d3993c7200faf2cc Mon Sep 17 00:00:00 2001
From: Svend Vanderveken
Date: Fri, 3 Jan 2014 12:27:39 +0100
Subject: [PATCH 021/121] updated install documentation: maven dependency
should have 'test' scope
---
README.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/README.md b/README.md
index ff514cb5..30a85064 100644
--- a/README.md
+++ b/README.md
@@ -77,6 +77,7 @@ To use, [download the JAR](https://github.com/skyscreamer/JSONassert/releases) o
org.skyscreamerjsonassert1.2.2
+ test
Write tests like this:
From 3851ea541f16f55f352fd1d3c4f8d657a51253fb Mon Sep 17 00:00:00 2001
From: Duncan Mackinder
Date: Mon, 13 Jan 2014 23:43:01 +0000
Subject: [PATCH 022/121] Regex and array size verification enhancements
Adding regular expression customization and value matchers and array
size comparator enhancements.
---
.../skyscreamer/jsonassert/Customizable.java | 16 ++++
.../skyscreamer/jsonassert/Customization.java | 16 +++-
.../RegularExpressionCustomization.java | 40 +++++++++
.../RegularExpressionValueMatcher.java | 37 ++++++++
.../comparator/ArraySizeComparator.java | 54 +++++++++++
.../comparator/CustomComparator.java | 36 ++++++--
.../RegularExpressionCustomizationTest.java | 89 +++++++++++++++++++
.../RegularExpressionValueMatcherTest.java | 49 ++++++++++
.../comparator/ArraySizeComparatorTest.java | 72 +++++++++++++++
9 files changed, 400 insertions(+), 9 deletions(-)
create mode 100644 src/main/java/org/skyscreamer/jsonassert/Customizable.java
create mode 100644 src/main/java/org/skyscreamer/jsonassert/RegularExpressionCustomization.java
create mode 100644 src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java
create mode 100644 src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java
create mode 100644 src/test/java/org/skyscreamer/jsonassert/RegularExpressionCustomizationTest.java
create mode 100644 src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java
create mode 100644 src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java
diff --git a/src/main/java/org/skyscreamer/jsonassert/Customizable.java b/src/main/java/org/skyscreamer/jsonassert/Customizable.java
new file mode 100644
index 00000000..27315255
--- /dev/null
+++ b/src/main/java/org/skyscreamer/jsonassert/Customizable.java
@@ -0,0 +1,16 @@
+package org.skyscreamer.jsonassert;
+
+/**
+ * Interface implemented by classes that determine if JSON elements require
+ * custom comparisons when compared by CustomComparator.
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public interface Customizable {
+
+ public abstract boolean appliesToPath(String path);
+
+ public abstract boolean matches(Object actual, Object expected);
+
+}
\ No newline at end of file
diff --git a/src/main/java/org/skyscreamer/jsonassert/Customization.java b/src/main/java/org/skyscreamer/jsonassert/Customization.java
index 71155a0b..f97607d3 100644
--- a/src/main/java/org/skyscreamer/jsonassert/Customization.java
+++ b/src/main/java/org/skyscreamer/jsonassert/Customization.java
@@ -3,7 +3,7 @@
/**
* Associates a custom matcher to a specific jsonpath.
*/
-public final class Customization {
+public final class Customization implements Customizable {
private final String path;
private final ValueMatcher comparator;
@@ -14,15 +14,23 @@ public Customization(String path, ValueMatcher comparator) {
this.comparator = comparator;
}
- public static Customization customization(String path, ValueMatcher comparator) {
+ public static Customizable customization(String path, ValueMatcher comparator) {
return new Customization(path, comparator);
}
- public boolean appliesToPath(String path) {
+ /* (non-Javadoc)
+ * @see org.skyscreamer.jsonassert.Customizable#appliesToPath(java.lang.String)
+ */
+ @Override
+ public boolean appliesToPath(String path) {
return this.path.equals(path);
}
- public boolean matches(Object actual, Object expected) {
+ /* (non-Javadoc)
+ * @see org.skyscreamer.jsonassert.Customizable#matches(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean matches(Object actual, Object expected) {
return comparator.equal(actual, expected);
}
}
diff --git a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionCustomization.java b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionCustomization.java
new file mode 100644
index 00000000..04771e1c
--- /dev/null
+++ b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionCustomization.java
@@ -0,0 +1,40 @@
+package org.skyscreamer.jsonassert;
+
+import java.util.regex.Pattern;
+
+/**
+ * Associates a custom matcher to a jsonpath identified by a regular expression
+ *
+ * @author Duncan Mackinder
+ */
+public final class RegularExpressionCustomization implements Customizable {
+ private final Pattern path;
+ private final ValueMatcher comparator;
+
+ public RegularExpressionCustomization(String path, ValueMatcher comparator) {
+ assert path != null;
+ assert comparator != null;
+ this.path = Pattern.compile(path);
+ this.comparator = comparator;
+ }
+
+ public static Customizable customization(String path, ValueMatcher comparator) {
+ return new RegularExpressionCustomization(path, comparator);
+ }
+
+ /* (non-Javadoc)
+ * @see org.skyscreamer.jsonassert.Customizable#appliesToPath(java.lang.String)
+ */
+ @Override
+ public boolean appliesToPath(String path) {
+ return this.path.matcher(path).matches();
+ }
+
+ /* (non-Javadoc)
+ * @see org.skyscreamer.jsonassert.Customizable#matches(java.lang.Object, java.lang.Object)
+ */
+ @Override
+ public boolean matches(Object actual, Object expected) {
+ return comparator.equal(actual, expected);
+ }
+}
diff --git a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java
new file mode 100644
index 00000000..a900e510
--- /dev/null
+++ b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java
@@ -0,0 +1,37 @@
+package org.skyscreamer.jsonassert;
+
+import java.util.regex.Pattern;
+
+import org.skyscreamer.jsonassert.ValueMatcher;
+
+/**
+ * A JSONassert value matcher that matches actual value to regular expression.
+ * If non-null regular expression passed to constructor, then all actual values
+ * will be compared against this pattern, ignoring any expected value passed to
+ * equal method. If null regular expression passed to constructor, then expected
+ * value passed to equals method will be treated as a regular expression.
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public class RegularExpressionValueMatcher implements ValueMatcher {
+
+ private final Pattern expectedPattern;
+
+ public RegularExpressionValueMatcher() {
+ this(null);
+ }
+
+ public RegularExpressionValueMatcher(String expected) {
+ expectedPattern = expected == null ? null : Pattern.compile(expected);
+ }
+
+ @Override
+ public boolean equal(T actual, T expected) {
+ String actualString = actual.toString();
+ Pattern pattern = expectedPattern != null ? expectedPattern : Pattern
+ .compile(expected.toString());
+ return pattern.matcher(actualString).matches();
+ }
+
+}
diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java
new file mode 100644
index 00000000..86eb50a6
--- /dev/null
+++ b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java
@@ -0,0 +1,54 @@
+package org.skyscreamer.jsonassert.comparator;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.skyscreamer.jsonassert.JSONCompareMode;
+import org.skyscreamer.jsonassert.JSONCompareResult;
+
+/**
+ * A JSONAssert array size comparator. Expected array should consist of either 1
+ * or 2 integer values that define maximum and minimum size of that the actual
+ * array is expected to be. If expected array contains a single integer value
+ * then the actual array must contain exactly that number of elements.
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public class ArraySizeComparator extends DefaultComparator {
+
+ public ArraySizeComparator(JSONCompareMode mode) {
+ super(mode);
+ }
+
+ @Override
+ public void compareJSONArray(String prefix, JSONArray expected,
+ JSONArray actual, JSONCompareResult result) throws JSONException {
+ if (expected.length() < 1 || expected.length() > 2) {
+ result.fail(prefix + ": invalid expectation, length=" + expected.length());
+ return;
+ }
+ if (!(expected.get(0) instanceof Number)) {
+ result.fail(prefix + ": min expected length not a number: " + expected.get(0));
+ return;
+ }
+ if ((expected.length() == 2 && !(expected.get(1) instanceof Number))) {
+ result.fail(prefix + ": max expected length not a number: " + expected.get(1));
+ return;
+ }
+ int minExpectedLength = expected.getInt(0);
+ if (minExpectedLength < 0) {
+ result.fail(prefix + ": invalid expectation, invalid min expected length: " + minExpectedLength);
+ return;
+ }
+ int maxExpectedLength = expected.length() == 2? expected.getInt(1): minExpectedLength;
+ if (maxExpectedLength < minExpectedLength) {
+ result.fail(prefix + ": invalid expectation, invalid expected length range: "+ minExpectedLength+" to " + maxExpectedLength);
+ return;
+ }
+ if (actual.length() < minExpectedLength || actual.length() > maxExpectedLength) {
+ result.fail(prefix + "[]: Expected " + minExpectedLength + (expected.length() == 2? (" to "+maxExpectedLength): "")
+ + " values but got " + actual.length());
+ }
+ }
+
+}
diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
index 7a9565ea..19752a4a 100644
--- a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
+++ b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
@@ -1,6 +1,7 @@
package org.skyscreamer.jsonassert.comparator;
import org.json.JSONException;
+import org.skyscreamer.jsonassert.Customizable;
import org.skyscreamer.jsonassert.Customization;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONCompareResult;
@@ -10,16 +11,41 @@
public class CustomComparator extends DefaultComparator {
- private final Collection customizations;
+ private final Collection customizations;
- public CustomComparator(JSONCompareMode mode, Customization... customizations) {
+ /**
+ * Create custom comparator from array of customizations.
+ *
+ * @param mode
+ * comparison mode
+ * @param customizations
+ * array of customizations
+ */
+ public CustomComparator(JSONCompareMode mode, Customizable... customizations) {
super(mode);
this.customizations = Arrays.asList(customizations);
}
+ /**
+ * Create custom comparator from array of customizations. Provides backwards
+ * compatibility with code compiled against JSONassert 1.2.1 or earlier. Use
+ * CustomComparator(JSONCompareMode mode, Customizable... customizations)
+ * constructor in place of this one.
+ *
+ * @param mode
+ * comparison mode
+ * @param customizations
+ * array of customizations
+ */
+ @Deprecated
+ public CustomComparator(JSONCompareMode mode, Customization... customizations) {
+ super(mode);
+ this.customizations = Arrays.asList((Customizable[])customizations);
+ }
+
@Override
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException {
- Customization customization = getCustomization(prefix);
+ Customizable customization = getCustomization(prefix);
if (customization != null) {
if (!customization.matches(actualValue, expectedValue)) {
result.fail(prefix, expectedValue, actualValue);
@@ -29,8 +55,8 @@ public void compareValues(String prefix, Object expectedValue, Object actualValu
}
}
- private Customization getCustomization(String path) {
- for (Customization c : customizations)
+ private Customizable getCustomization(String path) {
+ for (Customizable c : customizations)
if (c.appliesToPath(path))
return c;
return null;
diff --git a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionCustomizationTest.java b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionCustomizationTest.java
new file mode 100644
index 00000000..d4248039
--- /dev/null
+++ b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionCustomizationTest.java
@@ -0,0 +1,89 @@
+package org.skyscreamer.jsonassert;
+
+/**
+ * Unit tests for RegularExpressionCustomization
+ *
+ * @author Duncan Mackinder
+ *
+ */
+import org.json.JSONException;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.comparator.CustomComparator;
+import org.skyscreamer.jsonassert.comparator.JSONComparator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.skyscreamer.jsonassert.JSONCompare.compareJSON;
+
+public class RegularExpressionCustomizationTest {
+
+ String actual = "{\"first\":\"actual\", \"second\":1, \"third\":\"actual\"}";
+ String expected = "{\"first\":\"expected\", \"second\":1, \"third\":\"expected\"}";
+
+ String deepActual = "{\n" +
+ " \"outer\":\n" +
+ " {\n" +
+ " \"inner\":\n" +
+ " [\n" +
+ " {\n" +
+ " \"value\": \"actual\",\n" +
+ " \"otherValue\": \"foo\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"value\": \"actual\",\n" +
+ " \"otherValue\": \"bar\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"value\": \"actual\",\n" +
+ " \"otherValue\": \"baz\"\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ "}";
+ String deepExpected = "{\n" +
+ " \"outer\":\n" +
+ " {\n" +
+ " \"inner\":\n" +
+ " [\n" +
+ " {\n" +
+ " \"value\": \"expected\",\n" +
+ " \"otherValue\": \"foo\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"value\": \"expected\",\n" +
+ " \"otherValue\": \"bar\"\n" +
+ " },\n" +
+ " {\n" +
+ " \"value\": \"expected\",\n" +
+ " \"otherValue\": \"baz\"\n" +
+ " }\n" +
+ " ]\n" +
+ " }\n" +
+ "}";
+
+ int comparatorCallCount = 0;
+ ValueMatcher comparator = new ValueMatcher() {
+ @Override
+ public boolean equal(Object o1, Object o2) {
+ comparatorCallCount++;
+ return o1.toString().equals("actual") && o2.toString().equals("expected");
+ }
+ };
+
+ @Test
+ public void whenPathMatchesInCustomizationThenCallCustomMatcher() throws JSONException {
+ JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new RegularExpressionCustomization(".*i.*", comparator)); // will match first and third but not second
+ JSONCompareResult result = compareJSON(expected, actual, jsonCmp);
+ assertTrue(result.getMessage(), result.passed());
+ assertEquals(2, comparatorCallCount);
+ }
+
+ @Test
+ public void whenDeepPathMatchesCallCustomMatcher() throws JSONException {
+ JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new RegularExpressionCustomization("outer\\.inner\\[.*\\]\\.value", comparator));
+ JSONCompareResult result = compareJSON(deepExpected, deepActual, jsonCmp);
+ assertTrue(result.getMessage(), result.passed());
+ assertEquals(3, comparatorCallCount);
+ }
+
+}
diff --git a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java
new file mode 100644
index 00000000..c6962774
--- /dev/null
+++ b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java
@@ -0,0 +1,49 @@
+package org.skyscreamer.jsonassert;
+
+import org.json.JSONException;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.Customization;
+import org.skyscreamer.jsonassert.JSONCompareMode;
+import org.skyscreamer.jsonassert.comparator.CustomComparator;
+
+/**
+ * Unit tests for RegularExpressionValueMatcher
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public class RegularExpressionValueMatcherTest {
+ private void doTest(String jsonPath, String regex, String expectedJSON,
+ String actualJSON) throws JSONException {
+ JSONAssert.assertEquals(expectedJSON, actualJSON, new CustomComparator(
+ JSONCompareMode.STRICT_ORDER, new Customization(jsonPath,
+ new RegularExpressionValueMatcher(regex))));
+ }
+
+ @Test
+ public void fixedRegexMatchesStringAttributeInsideArray() throws JSONException {
+ doTest("d.results[0].__metadata.uri", "http://localhost:80/Person\\('\\d+'\\)", "{d:{results:[{__metadata:{uri:X}}]}}", "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person('1')\",type:Person},id:1}]}}");
+ }
+
+ @Test
+ public void fixedRegexWithSimplePathMatchsStringAttribute() throws JSONException {
+ doTest("a", "v.", "{a:x}", "{a:v1}");
+ }
+
+ @Test
+ public void fixedRegexWithThreeLevelPathMatchsStringAttribute() throws JSONException {
+ doTest("a.b.c", ".*Is.*", "{a:{b:{c:x}}}", "{a:{b:{c:thisIsAString}}}");
+ }
+
+ @Test
+ public void dynamicRegexWithSimplePathMatchsStringAttribute() throws JSONException {
+ doTest("a", null, "{a:\"v.\"}", "{a:v1}");
+ }
+
+ @Test
+ public void dynamicRegexWithThreeLevelPathMatchsStringAttribute() throws JSONException {
+ doTest("a.b.c", null, "{a:{b:{c:\".*Is.*\"}}}",
+ "{a:{b:{c:thisIsAString}}}");
+ }
+
+}
diff --git a/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java b/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java
new file mode 100644
index 00000000..3a734765
--- /dev/null
+++ b/src/test/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparatorTest.java
@@ -0,0 +1,72 @@
+package org.skyscreamer.jsonassert.comparator;
+
+import org.json.JSONException;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.JSONAssert;
+import org.skyscreamer.jsonassert.JSONCompareMode;
+
+/**
+ * Unit tests for ArraySizeComparator
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public class ArraySizeComparatorTest {
+ private static final String twoElementArray = "{a:[b,c]}";
+
+ private void doTest(String expectedJSON, String actualJSON) throws JSONException
+ {
+ JSONAssert.assertEquals(expectedJSON, actualJSON, new ArraySizeComparator(JSONCompareMode.STRICT_ORDER));
+ }
+
+ @Test
+ public void succeedsWhenExactSizeExpected() throws JSONException {
+ doTest("{a:[2]}", twoElementArray);
+ }
+
+ @Test
+ public void succeedsWhenSizeWithinExpectedRange() throws JSONException {
+ doTest("{a:[1,3]}", twoElementArray);
+ }
+
+ @Test
+ public void succeedsWhenSizeIsMinimumOfExpectedRange() throws JSONException {
+ doTest("{a:[2,4]}", twoElementArray);
+ }
+
+ @Test
+ public void succeedsWhenSizeIsMaximumOfExpectedRange() throws JSONException {
+ doTest("{a:[1,2]}", twoElementArray);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void failsWhenExpectedArrayTooShort() throws JSONException {
+ doTest("{a:[]}", twoElementArray);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void failsWhenExpectedArrayTooLong() throws JSONException {
+ doTest("{a:[1,2,3]}", twoElementArray);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void failsWhenExpectedNotAllSimpleTypes() throws JSONException {
+ doTest("{a:[{y:1},2]}", twoElementArray);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void failsWhenExpectedNotAllSimpleInteger() throws JSONException {
+ doTest("{a:[Z,2]}", twoElementArray);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void failsWhenExpectedMinimumTooSmall() throws JSONException {
+ doTest("{a:[-1,6]}", twoElementArray);
+ }
+
+ @Test(expected=AssertionError.class)
+ public void failsWhenExpectedMaximumTooSmall() throws JSONException {
+ doTest("{a:[8,6]}", twoElementArray);
+ }
+
+}
From 6c00a7c7a8e9c1958ee4332fbf91e3d1f75ffce3 Mon Sep 17 00:00:00 2001
From: Duncan Mackinder
Date: Sun, 19 Jan 2014 16:13:26 +0000
Subject: [PATCH 023/121] Add ArrayValueMatcher, improve diagnostics
Add ArrayValueMatcher to simplify verification of range of array
elements
Improve diagnostics from RegularExpressionValueMatcher
Remove RegularExpressionCustomization as it did not prove useful
---
.../jsonassert/ArrayValueMatcher.java | 106 ++++++++++++
.../skyscreamer/jsonassert/Customizable.java | 16 --
.../skyscreamer/jsonassert/Customization.java | 22 +--
.../jsonassert/JSONCompareResult.java | 10 ++
.../jsonassert/LocationAwareValueMatcher.java | 15 ++
.../RegularExpressionCustomization.java | 40 -----
.../RegularExpressionValueMatcher.java | 61 ++++++-
.../jsonassert/ValueMatcherException.java | 48 ++++++
.../comparator/CustomComparator.java | 48 ++----
.../comparator/DefaultComparator.java | 6 -
.../jsonassert/ArrayValueMatcherTest.java | 159 ++++++++++++++++++
.../RegularExpressionCustomizationTest.java | 89 ----------
.../RegularExpressionValueMatcherTest.java | 64 ++++++-
13 files changed, 471 insertions(+), 213 deletions(-)
create mode 100644 src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java
delete mode 100644 src/main/java/org/skyscreamer/jsonassert/Customizable.java
create mode 100644 src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java
delete mode 100644 src/main/java/org/skyscreamer/jsonassert/RegularExpressionCustomization.java
create mode 100644 src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java
create mode 100644 src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java
delete mode 100644 src/test/java/org/skyscreamer/jsonassert/RegularExpressionCustomizationTest.java
diff --git a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java
new file mode 100644
index 00000000..218c3998
--- /dev/null
+++ b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java
@@ -0,0 +1,106 @@
+package org.skyscreamer.jsonassert;
+
+import java.text.MessageFormat;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.skyscreamer.jsonassert.comparator.JSONComparator;
+
+/**
+ * A value matcher for arrays. This operates like STRICT_ORDER array match,
+ * however if expected array has less elements than actual array the matching
+ * process loops through the expected array to get expected elements for the
+ * additional actual elements. In general the expected array will contain a
+ * single element which is matched against each actual array element in turn.
+ * This allows simple verification of constant array element components and
+ * coupled with RegularExpressionValueMatcher can be used to match specific
+ * array element components against a regular expression pattern. If the
+ * expected object is not an array, a one element expected array is created
+ * containing whatever is provided as the expected value.
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public class ArrayValueMatcher implements LocationAwareValueMatcher {
+ private final JSONComparator comparator;
+ private final int from;
+ private final int to;
+
+ /**
+ * Create ArrayValueMatcher to match every element in actual array against
+ * elements taken in sequence from expected array, repeating from start of
+ * expected array if necessary.
+ *
+ * @param comparator
+ * comparator to use to compare elements
+ */
+ public ArrayValueMatcher(JSONComparator comparator) {
+ this(comparator, 0, Integer.MAX_VALUE);
+ }
+
+ /**
+ * Create ArrayValueMatcher to match specified element in actual array
+ * against first element of expected array.
+ *
+ * @param comparator
+ * comparator to use to compare elements
+ */
+ public ArrayValueMatcher(JSONComparator comparator, int i) {
+ this(comparator, i, i);
+ }
+
+ /**
+ * Create ArrayValueMatcher to match every element in specified range
+ * (inclusive) from actual array against elements taken in sequence from
+ * expected array, repeating from start of expected array if necessary.
+ *
+ * @param comparator
+ * comparator to use to compare elements
+ * @from first element in actual array to compare
+ * @to last element in actual array to compare
+ */
+ public ArrayValueMatcher(JSONComparator comparator, int from, int to) {
+ assert comparator != null : "comparator null";
+ assert from >= 0 : MessageFormat.format("from({0}) < 0", from);
+ assert to >= from : MessageFormat.format("to({0}) < from({1})", to,
+ from);
+ this.comparator = comparator;
+ this.from = from;
+ this.to = to;
+ }
+
+ @Override
+ /*
+ * NOTE: method defined as required by ValueMatcher interface but will never
+ * be called so defined simply to indicate match failure
+ */
+ public boolean equal(T o1, T o2) {
+ return false;
+ }
+
+ @Override
+ public boolean equal(String prefix, T actual, T expected, JSONCompareResult result) {
+ if (!(actual instanceof JSONArray)) {
+ throw new IllegalArgumentException("ArrayValueMatcher applied to non-array actual value");
+ }
+ try {
+ JSONArray actualArray = (JSONArray) actual;
+ JSONArray expectedArray = expected instanceof JSONArray ? (JSONArray) expected: new JSONArray(new Object[] { expected });
+ int first = Math.max(0, from);
+ int last = Math.min(actualArray.length() - 1, to);
+ int expectedLen = expectedArray.length();
+ for (int i = first; i <= last; i++) {
+ String elementPrefix = MessageFormat.format("{0}[{1}]", prefix, i);
+ Object actualElement = actualArray.get(i);
+ Object expectedElement = expectedArray.get((i - first) % expectedLen);
+ comparator.compareValues(elementPrefix, expectedElement, actualElement, result);
+ }
+ // values must match since no exceptions thrown
+ return true;
+ }
+ catch (JSONException e) {
+ return false;
+ }
+ }
+
+}
diff --git a/src/main/java/org/skyscreamer/jsonassert/Customizable.java b/src/main/java/org/skyscreamer/jsonassert/Customizable.java
deleted file mode 100644
index 27315255..00000000
--- a/src/main/java/org/skyscreamer/jsonassert/Customizable.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package org.skyscreamer.jsonassert;
-
-/**
- * Interface implemented by classes that determine if JSON elements require
- * custom comparisons when compared by CustomComparator.
- *
- * @author Duncan Mackinder
- *
- */
-public interface Customizable {
-
- public abstract boolean appliesToPath(String path);
-
- public abstract boolean matches(Object actual, Object expected);
-
-}
\ No newline at end of file
diff --git a/src/main/java/org/skyscreamer/jsonassert/Customization.java b/src/main/java/org/skyscreamer/jsonassert/Customization.java
index f97607d3..c84dab66 100644
--- a/src/main/java/org/skyscreamer/jsonassert/Customization.java
+++ b/src/main/java/org/skyscreamer/jsonassert/Customization.java
@@ -3,7 +3,7 @@
/**
* Associates a custom matcher to a specific jsonpath.
*/
-public final class Customization implements Customizable {
+public final class Customization {
private final String path;
private final ValueMatcher comparator;
@@ -14,23 +14,19 @@ public Customization(String path, ValueMatcher comparator) {
this.comparator = comparator;
}
- public static Customizable customization(String path, ValueMatcher comparator) {
+ public static Customization customization(String path, ValueMatcher comparator) {
return new Customization(path, comparator);
}
- /* (non-Javadoc)
- * @see org.skyscreamer.jsonassert.Customizable#appliesToPath(java.lang.String)
- */
- @Override
public boolean appliesToPath(String path) {
return this.path.equals(path);
}
- /* (non-Javadoc)
- * @see org.skyscreamer.jsonassert.Customizable#matches(java.lang.Object, java.lang.Object)
- */
- @Override
- public boolean matches(Object actual, Object expected) {
- return comparator.equal(actual, expected);
- }
+ public boolean matches(String prefix, Object actual, Object expected,
+ JSONCompareResult result) {
+ if (comparator instanceof LocationAwareValueMatcher) {
+ return ((LocationAwareValueMatcher)comparator).equal(prefix, actual, expected, result);
+ }
+ return comparator.equal(actual, expected);
+ }
}
diff --git a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java
index 3b821b46..2b772ac0 100644
--- a/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java
+++ b/src/main/java/org/skyscreamer/jsonassert/JSONCompareResult.java
@@ -127,6 +127,16 @@ public JSONCompareResult fail(String field, Object expected, Object actual) {
return this;
}
+ /**
+ * Identify that the comparison failed
+ * @param field Which field failed
+ * @param exception exception containing details of match failure
+ */
+ public JSONCompareResult fail(String field, ValueMatcherException exception) {
+ fail(field + ": " + exception.getMessage(), exception.getExpected(), exception.getActual());
+ return this;
+ }
+
private String formatFailureMessage(String field, Object expected, Object actual) {
return field
+ "\nExpected: "
diff --git a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java
new file mode 100644
index 00000000..879747f2
--- /dev/null
+++ b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java
@@ -0,0 +1,15 @@
+/**
+ *
+ */
+package org.skyscreamer.jsonassert;
+
+/**
+ * A ValueMatcher extension that provides location in form of prefix to the equals method.
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public interface LocationAwareValueMatcher extends ValueMatcher {
+
+ boolean equal(String prefix, T actual, T expected, JSONCompareResult result);
+}
diff --git a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionCustomization.java b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionCustomization.java
deleted file mode 100644
index 04771e1c..00000000
--- a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionCustomization.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.skyscreamer.jsonassert;
-
-import java.util.regex.Pattern;
-
-/**
- * Associates a custom matcher to a jsonpath identified by a regular expression
- *
- * @author Duncan Mackinder
- */
-public final class RegularExpressionCustomization implements Customizable {
- private final Pattern path;
- private final ValueMatcher comparator;
-
- public RegularExpressionCustomization(String path, ValueMatcher comparator) {
- assert path != null;
- assert comparator != null;
- this.path = Pattern.compile(path);
- this.comparator = comparator;
- }
-
- public static Customizable customization(String path, ValueMatcher comparator) {
- return new RegularExpressionCustomization(path, comparator);
- }
-
- /* (non-Javadoc)
- * @see org.skyscreamer.jsonassert.Customizable#appliesToPath(java.lang.String)
- */
- @Override
- public boolean appliesToPath(String path) {
- return this.path.matcher(path).matches();
- }
-
- /* (non-Javadoc)
- * @see org.skyscreamer.jsonassert.Customizable#matches(java.lang.Object, java.lang.Object)
- */
- @Override
- public boolean matches(Object actual, Object expected) {
- return comparator.equal(actual, expected);
- }
-}
diff --git a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java
index a900e510..7efb64eb 100644
--- a/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java
+++ b/src/main/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcher.java
@@ -1,15 +1,17 @@
package org.skyscreamer.jsonassert;
import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
import org.skyscreamer.jsonassert.ValueMatcher;
/**
* A JSONassert value matcher that matches actual value to regular expression.
* If non-null regular expression passed to constructor, then all actual values
- * will be compared against this pattern, ignoring any expected value passed to
- * equal method. If null regular expression passed to constructor, then expected
- * value passed to equals method will be treated as a regular expression.
+ * will be compared against this constant pattern, ignoring any expected value
+ * passed to equal method. If null regular expression passed to constructor,
+ * then expected value passed to equals method will be used to dynamically
+ * specify regular expression pattern that actual value must match.
*
* @author Duncan Mackinder
*
@@ -18,20 +20,63 @@ public class RegularExpressionValueMatcher implements ValueMatcher {
private final Pattern expectedPattern;
+ /**
+ * Create RegularExpressionValueMatcher in which the pattern the actual
+ * value must match with be specified dynamically from the expected string
+ * passed to this matcher in the equals method.
+ */
public RegularExpressionValueMatcher() {
this(null);
}
- public RegularExpressionValueMatcher(String expected) {
- expectedPattern = expected == null ? null : Pattern.compile(expected);
+ /**
+ * Create RegularExpressionValueMatcher with specified pattern. If pattern
+ * is not null, it must be a valid regular expression that defines a
+ * constant expected pattern that every actual value must match (in this
+ * case the expected value passed to equal method will be ignored). If
+ * pattern is null, the pattern the actual value must match with be
+ * specified dynamically from the expected string passed to this matcher in
+ * the equals method.
+ *
+ * @param pattern
+ * if non null, regular expression pattern which all actual
+ * values this matcher is applied to must match. If null, this
+ * matcher will apply pattern specified dynamically via the
+ * expected parameter to the equal method.
+ * @throws IllegalArgumentException
+ * if pattern is non-null and not a valid regular expression.
+ */
+ public RegularExpressionValueMatcher(String pattern) throws IllegalArgumentException {
+ try {
+ expectedPattern = pattern == null ? null : Pattern.compile(pattern);
+ }
+ catch (PatternSyntaxException e) {
+ throw new IllegalArgumentException("Constant expected pattern invalid: " + e.getMessage(), e);
+ }
}
@Override
public boolean equal(T actual, T expected) {
String actualString = actual.toString();
- Pattern pattern = expectedPattern != null ? expectedPattern : Pattern
- .compile(expected.toString());
- return pattern.matcher(actualString).matches();
+ String expectedString = expected.toString();
+ try {
+ Pattern pattern = isStaticPattern() ? expectedPattern : Pattern
+ .compile(expectedString);
+ if (!pattern.matcher(actualString).matches()) {
+ throw new ValueMatcherException(getPatternType() + " expected pattern did not match value", pattern.toString(), actualString);
+ }
+ }
+ catch (PatternSyntaxException e) {
+ throw new ValueMatcherException(getPatternType() + " expected pattern invalid: " + e.getMessage(), e, expectedString, actualString);
+ }
+ return true;
}
+ private boolean isStaticPattern() {
+ return expectedPattern != null;
+ }
+
+ private String getPatternType() {
+ return isStaticPattern()? "Constant": "Dynamic";
+ }
}
diff --git a/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java b/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java
new file mode 100644
index 00000000..de788cef
--- /dev/null
+++ b/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java
@@ -0,0 +1,48 @@
+package org.skyscreamer.jsonassert;
+
+/**
+ * Exception that may be thrown by ValueMatcher subclasses to provide more detail on why matches method failed.
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public class ValueMatcherException extends RuntimeException {
+ private static final long serialVersionUID = 1L;
+
+ private final String expected;
+
+ private final String actual;
+
+ public ValueMatcherException(String message, String expected, String actual) {
+ super(message);
+ this.expected = expected;
+ this.actual = actual;
+ }
+
+ public ValueMatcherException(Throwable cause, String expected, String actual) {
+ super(cause);
+ this.expected = expected;
+ this.actual = actual;
+ }
+
+ public ValueMatcherException(String message, Throwable cause, String expected, String actual) {
+ super(message, cause);
+ this.expected = expected;
+ this.actual = actual;
+ }
+
+ /**
+ * @return the expected value
+ */
+ public String getExpected() {
+ return expected;
+ }
+
+ /**
+ * @return the actual value
+ */
+ public String getActual() {
+ return actual;
+ }
+
+}
diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
index 19752a4a..af386c5b 100644
--- a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
+++ b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
@@ -1,62 +1,42 @@
package org.skyscreamer.jsonassert.comparator;
import org.json.JSONException;
-import org.skyscreamer.jsonassert.Customizable;
import org.skyscreamer.jsonassert.Customization;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONCompareResult;
+import org.skyscreamer.jsonassert.ValueMatcherException;
import java.util.Arrays;
import java.util.Collection;
public class CustomComparator extends DefaultComparator {
- private final Collection customizations;
+ private final Collection customizations;
- /**
- * Create custom comparator from array of customizations.
- *
- * @param mode
- * comparison mode
- * @param customizations
- * array of customizations
- */
- public CustomComparator(JSONCompareMode mode, Customizable... customizations) {
- super(mode);
- this.customizations = Arrays.asList(customizations);
- }
-
- /**
- * Create custom comparator from array of customizations. Provides backwards
- * compatibility with code compiled against JSONassert 1.2.1 or earlier. Use
- * CustomComparator(JSONCompareMode mode, Customizable... customizations)
- * constructor in place of this one.
- *
- * @param mode
- * comparison mode
- * @param customizations
- * array of customizations
- */
- @Deprecated
public CustomComparator(JSONCompareMode mode, Customization... customizations) {
super(mode);
- this.customizations = Arrays.asList((Customizable[])customizations);
+ this.customizations = Arrays.asList((Customization[])customizations);
}
@Override
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException {
- Customizable customization = getCustomization(prefix);
+ Customization customization = getCustomization(prefix);
if (customization != null) {
- if (!customization.matches(actualValue, expectedValue)) {
- result.fail(prefix, expectedValue, actualValue);
- }
+ try {
+ if (!customization.matches(prefix, actualValue, expectedValue, result)) {
+ result.fail(prefix, expectedValue, actualValue);
+ }
+ }
+ catch (ValueMatcherException e) {
+ result.fail(prefix, e);
+ }
} else {
super.compareValues(prefix, expectedValue, actualValue, result);
}
}
- private Customizable getCustomization(String path) {
- for (Customizable c : customizations)
+ private Customization getCustomization(String path) {
+ for (Customization c : customizations)
if (c.appliesToPath(path))
return c;
return null;
diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java
index d7ab30be..e2f6b57a 100644
--- a/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java
+++ b/src/main/java/org/skyscreamer/jsonassert/comparator/DefaultComparator.java
@@ -3,15 +3,9 @@
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-import org.skyscreamer.jsonassert.Customization;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONCompareResult;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.Set;
-
import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allJSONObjects;
import static org.skyscreamer.jsonassert.comparator.JSONCompareUtil.allSimpleValues;
diff --git a/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java
new file mode 100644
index 00000000..722588dc
--- /dev/null
+++ b/src/test/java/org/skyscreamer/jsonassert/ArrayValueMatcherTest.java
@@ -0,0 +1,159 @@
+package org.skyscreamer.jsonassert;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.text.MessageFormat;
+
+import org.json.JSONException;
+import org.junit.Test;
+import org.skyscreamer.jsonassert.comparator.ArraySizeComparator;
+import org.skyscreamer.jsonassert.comparator.CustomComparator;
+import org.skyscreamer.jsonassert.comparator.DefaultComparator;
+import org.skyscreamer.jsonassert.comparator.JSONComparator;
+
+/**
+ * Unit tests for ArrayValueMatcher
+ *
+ * @author Duncan Mackinder
+ *
+ */
+public class ArrayValueMatcherTest {
+
+ private static final String ARRAY_OF_JSONOBJECTS = "{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}]}";
+ private static final String ARRAY_OF_INTEGERS = "{a:[1,2,3,4,5]}";
+ private static final String ARRAY_OF_JSONARRAYS = "{a:[[7,8],[9,10],[12,13],[19,20,21]]}";
+ private static final JSONComparator comparator = new DefaultComparator(JSONCompareMode.LENIENT);
+
+ private void doTest(String jsonPath, ArrayValueMatcher arrayValueMatcher, String expectedJSON,
+ String actualJSON) throws JSONException {
+ 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 {
+ try {
+ doTest(jsonPath, arrayValueMatcher, expectedJSON, actualJSON);
+ }
+ catch (AssertionError e) {
+ String failureMessage = MessageFormat.format("Exception message ''{0}'', does not match expected pattern ''{1}''", e.getMessage(), expectedMessagePattern);
+ assertTrue(failureMessage, e.getMessage().matches(expectedMessagePattern));
+ return;
+ }
+ fail("AssertionError not thrown");
+ }
+
+ @Test
+ public void matchesSecondElementOfJSONObjectArray() throws JSONException {
+ doTest("a", new ArrayValueMatcher(comparator, 1), "{a:[{background:grey,id:2,type:row}]}", ARRAY_OF_JSONOBJECTS);
+ }
+
+ @Test
+ public void failsWhenSecondElementOfJSONObjectArrayDoesNotMatch() throws JSONException {
+ doFailingMatchTest("a",
+ new ArrayValueMatcher(comparator, 1),
+ "{a:[{background:DOES_NOT_MATCH,id:2,type:row}]}",
+ ARRAY_OF_JSONOBJECTS,
+ "a\\[1\\]\\.background\\s*Expected:\\s*DOES_NOT_MATCH\\s*got:\\s*grey\\s*");
+ }
+
+ @Test
+ public void failsWhenThirdElementOfJSONObjectArrayDoesNotMatchInMultiplePlaces() throws JSONException {
+ doFailingMatchTest("a",
+ new ArrayValueMatcher(comparator, 2),
+ "{a:[{background:DOES_NOT_MATCH,id:3,type:WRONG_TYPE}]}",
+ ARRAY_OF_JSONOBJECTS,
+ "a\\[2\\]\\.background\\s*Expected:\\s*DOES_NOT_MATCH\\s*got:\\s*white\\s*;\\s*a\\[2\\]\\.type\\s*Expected:\\s*WRONG_TYPE\\s*got:\\s*row\\s*");
+ }
+
+ @Test
+ public void failsWhenTwoElementsOfJSONObjectArrayDoNotMatch() throws JSONException {
+ doFailingMatchTest("a",
+ new ArrayValueMatcher(comparator, 1, 2),
+ "{a:[{background:DOES_NOT_MATCH,id:2,type:row},{background:white,id:3,type:WRONG_TYPE}]}",
+ ARRAY_OF_JSONOBJECTS,
+ "a\\[1\\]\\.background\\s*Expected:\\s*DOES_NOT_MATCH\\s*got:\\s*grey\\s*;\\s*a\\[2\\]\\.type\\s*Expected:\\s*WRONG_TYPE\\s*got:\\s*row\\s*");
+ }
+
+ @Test
+ public void matchesThirdElementOfSimpleValueArray() throws JSONException {
+ doTest("a", new ArrayValueMatcher(comparator, 2), "{a:[3]}", ARRAY_OF_INTEGERS);
+ }
+
+ @Test
+ public void failsWhenTwoElementOfSimpleValueArrayDoNotMatch() throws JSONException {
+ 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 {
+ doTest("a", new ArrayValueMatcher(comparator, 0), "{a:[[7,8]]}", ARRAY_OF_JSONARRAYS);
+ }
+
+ @Test
+ public void matchesSizeOfFirstThreeInnerArrays() throws JSONException {
+ JSONComparator innerArraySizeComparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER);
+ doTest("a", new ArrayValueMatcher(innerArraySizeComparator, 0, 2), "{a:[[2]]}", ARRAY_OF_JSONARRAYS);
+ }
+
+ @Test
+ public void failsWhenInnerArraySizeDoesNotMatch() throws JSONException {
+ JSONComparator innerArraySizeComparator = new ArraySizeComparator(JSONCompareMode.STRICT_ORDER);
+ doFailingMatchTest("a",
+ new ArrayValueMatcher(innerArraySizeComparator),
+ "{a:[[2]]}",
+ ARRAY_OF_JSONARRAYS,
+ "a\\[3\\]\\[\\]:\\s*Expected 2 values but got 3");
+ }
+
+ @Test
+ public void failsWhenInnerJSONObjectArrayElementDoesNotMatch() throws JSONException {
+ ArrayValueMatcher innerArrayValueMatcher = new ArrayValueMatcher(comparator, 1);
+ JSONComparator innerArrayComparator = new CustomComparator(
+ JSONCompareMode.LENIENT, new Customization("a[2]", innerArrayValueMatcher));
+ doFailingMatchTest("a",
+ new ArrayValueMatcher(innerArrayComparator, 2), // tests inner array i.e. [12,13]
+ "{a:[[14]]}",
+ ARRAY_OF_JSONARRAYS,
+ "a\\[2\\]\\[1\\]\\s*Expected:\\s*14\\s*got:\\s*13\\s*");
+ }
+
+ @Test
+ public void matchesEveryElementOfJSONObjectArray() throws JSONException {
+ doTest("a", new ArrayValueMatcher(comparator), "{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS);
+ }
+
+ @Test
+ public void matchesEveryElementOfJSONObjectArrayWhenRangeTooLarge() throws JSONException {
+ doTest("a", new ArrayValueMatcher(comparator, 0, 500), "{a:[{type:row}]}", ARRAY_OF_JSONOBJECTS);
+ }
+
+ @Test
+ public void matchesElementPairsStartingFromElement1OfJSONObjectArrayWhenRangeTooLarge() throws JSONException {
+ doTest("a", new ArrayValueMatcher(comparator, 1, 500), "{a:[{background:grey},{background:white}]}", ARRAY_OF_JSONOBJECTS);
+ }
+
+ @Test
+ public void matchesElementPairsStartingFromElement0OfJSONObjectArrayWhenRangeTooLarge() throws JSONException {
+ doTest("a", new ArrayValueMatcher(comparator), "{a:[{background:white},{background:grey}]}", ARRAY_OF_JSONOBJECTS);
+ }
+
+ /*
+ * Following tests verify the ability to match an element containing either
+ * a simple value or a JSON object against simple value or JSON object
+ * without requiring expected value to be wrapped in an array reducing
+ * slightly the syntactic load on teh test author & reader.
+ */
+
+ @Test
+ public void simpleValueMatchesSecondElementOfJSONObjectArray() throws JSONException {
+ doTest("a", new ArrayValueMatcher(comparator, 3), "{a:4}", ARRAY_OF_INTEGERS);
+ }
+
+ @Test
+ public void jsonObjectMatchesSecondElementOfJSONObjectArray() throws JSONException {
+ doTest("a", new ArrayValueMatcher(comparator, 1), "{a:{background:grey,id:2,type:row}}", ARRAY_OF_JSONOBJECTS);
+ }
+
+}
diff --git a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionCustomizationTest.java b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionCustomizationTest.java
deleted file mode 100644
index d4248039..00000000
--- a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionCustomizationTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-package org.skyscreamer.jsonassert;
-
-/**
- * Unit tests for RegularExpressionCustomization
- *
- * @author Duncan Mackinder
- *
- */
-import org.json.JSONException;
-import org.junit.Test;
-import org.skyscreamer.jsonassert.comparator.CustomComparator;
-import org.skyscreamer.jsonassert.comparator.JSONComparator;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.skyscreamer.jsonassert.JSONCompare.compareJSON;
-
-public class RegularExpressionCustomizationTest {
-
- String actual = "{\"first\":\"actual\", \"second\":1, \"third\":\"actual\"}";
- String expected = "{\"first\":\"expected\", \"second\":1, \"third\":\"expected\"}";
-
- String deepActual = "{\n" +
- " \"outer\":\n" +
- " {\n" +
- " \"inner\":\n" +
- " [\n" +
- " {\n" +
- " \"value\": \"actual\",\n" +
- " \"otherValue\": \"foo\"\n" +
- " },\n" +
- " {\n" +
- " \"value\": \"actual\",\n" +
- " \"otherValue\": \"bar\"\n" +
- " },\n" +
- " {\n" +
- " \"value\": \"actual\",\n" +
- " \"otherValue\": \"baz\"\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- "}";
- String deepExpected = "{\n" +
- " \"outer\":\n" +
- " {\n" +
- " \"inner\":\n" +
- " [\n" +
- " {\n" +
- " \"value\": \"expected\",\n" +
- " \"otherValue\": \"foo\"\n" +
- " },\n" +
- " {\n" +
- " \"value\": \"expected\",\n" +
- " \"otherValue\": \"bar\"\n" +
- " },\n" +
- " {\n" +
- " \"value\": \"expected\",\n" +
- " \"otherValue\": \"baz\"\n" +
- " }\n" +
- " ]\n" +
- " }\n" +
- "}";
-
- int comparatorCallCount = 0;
- ValueMatcher comparator = new ValueMatcher() {
- @Override
- public boolean equal(Object o1, Object o2) {
- comparatorCallCount++;
- return o1.toString().equals("actual") && o2.toString().equals("expected");
- }
- };
-
- @Test
- public void whenPathMatchesInCustomizationThenCallCustomMatcher() throws JSONException {
- JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new RegularExpressionCustomization(".*i.*", comparator)); // will match first and third but not second
- JSONCompareResult result = compareJSON(expected, actual, jsonCmp);
- assertTrue(result.getMessage(), result.passed());
- assertEquals(2, comparatorCallCount);
- }
-
- @Test
- public void whenDeepPathMatchesCallCustomMatcher() throws JSONException {
- JSONComparator jsonCmp = new CustomComparator(JSONCompareMode.STRICT, new RegularExpressionCustomization("outer\\.inner\\[.*\\]\\.value", comparator));
- JSONCompareResult result = compareJSON(deepExpected, deepActual, jsonCmp);
- assertTrue(result.getMessage(), result.passed());
- assertEquals(3, comparatorCallCount);
- }
-
-}
diff --git a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java
index c6962774..cffedac1 100644
--- a/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java
+++ b/src/test/java/org/skyscreamer/jsonassert/RegularExpressionValueMatcherTest.java
@@ -1,5 +1,7 @@
package org.skyscreamer.jsonassert;
+import org.junit.Assert;
+
import org.json.JSONException;
import org.junit.Test;
import org.skyscreamer.jsonassert.Customization;
@@ -13,6 +15,10 @@
*
*/
public class RegularExpressionValueMatcherTest {
+ private static final String ARRAY_ELEMENT_PREFIX = "d.results[0].__metadata.uri";
+ private static final String JSON_STRING_WITH_ARRAY = "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person('1')\",type:Person},id:1}]}}";
+ 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 {
JSONAssert.assertEquals(expectedJSON, actualJSON, new CustomComparator(
@@ -21,17 +27,12 @@ JSONCompareMode.STRICT_ORDER, new Customization(jsonPath,
}
@Test
- public void fixedRegexMatchesStringAttributeInsideArray() throws JSONException {
- doTest("d.results[0].__metadata.uri", "http://localhost:80/Person\\('\\d+'\\)", "{d:{results:[{__metadata:{uri:X}}]}}", "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person('1')\",type:Person},id:1}]}}");
- }
-
- @Test
- public void fixedRegexWithSimplePathMatchsStringAttribute() throws JSONException {
+ public void constantRegexWithSimplePathMatchsStringAttribute() throws JSONException {
doTest("a", "v.", "{a:x}", "{a:v1}");
}
@Test
- public void fixedRegexWithThreeLevelPathMatchsStringAttribute() throws JSONException {
+ public void constantRegexWithThreeLevelPathMatchsStringAttribute() throws JSONException {
doTest("a.b.c", ".*Is.*", "{a:{b:{c:x}}}", "{a:{b:{c:thisIsAString}}}");
}
@@ -46,4 +47,53 @@ public void dynamicRegexWithThreeLevelPathMatchsStringAttribute() throws JSONExc
"{a:{b:{c:thisIsAString}}}");
}
+ @Test
+ public void constantRegexMatchesStringAttributeInsideArray() throws JSONException {
+ doTest(ARRAY_ELEMENT_PREFIX, "http://localhost:80/Person\\('\\d+'\\)", CONSTANT_URI_REGEX_EXPECTED_JSON, JSON_STRING_WITH_ARRAY);
+ }
+
+ @Test
+ public void dynamicRegexMatchesStringAttributeInsideArray() throws JSONException {
+ doTest(ARRAY_ELEMENT_PREFIX, null, "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person\\\\('\\\\d+'\\\\)\"}}]}}", JSON_STRING_WITH_ARRAY);
+ }
+
+ @Test
+ public void failsWhenDynamicRegexInvalid() throws JSONException {
+ try {
+ doTest(ARRAY_ELEMENT_PREFIX, null, "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person('\\\\d+'\\\\)\"}}]}}", JSON_STRING_WITH_ARRAY);
+ }
+ catch (AssertionError e) {
+ Assert.assertTrue("Invalid exception message returned: "+ e.getMessage(), e.getMessage().startsWith(ARRAY_ELEMENT_PREFIX + ": Dynamic expected pattern invalid: "));
+ }
+ }
+
+ @Test
+ public void failsWhenDynamicRegexDoesNotMatchStringAttributeInsideArray() throws JSONException {
+ try {
+ doTest(ARRAY_ELEMENT_PREFIX, null, "{d:{results:[{__metadata:{uri:\"http://localhost:80/Person\\\\('\\\\w+'\\\\)\"}}]}}", JSON_STRING_WITH_ARRAY);
+ }
+ catch (AssertionError e) {
+ Assert.assertTrue("Invalid exception message returned: "+ e.getMessage(), e.getMessage().startsWith(ARRAY_ELEMENT_PREFIX + ": Dynamic expected pattern did not match value"));
+ }
+ }
+
+ @Test
+ public void failsWhenConstantRegexInvalid() throws JSONException {
+ try {
+ doTest(ARRAY_ELEMENT_PREFIX, "http://localhost:80/Person\\\\['\\\\d+'\\\\)", CONSTANT_URI_REGEX_EXPECTED_JSON, JSON_STRING_WITH_ARRAY);
+ }
+ catch (IllegalArgumentException e) {
+ Assert.assertTrue("Invalid exception message returned: "+ e.getMessage(), e.getMessage().startsWith("Constant expected pattern invalid: "));
+ }
+ }
+
+ @Test
+ public void failsWhenConstantRegexDoesNotMatchStringAttributeInsideArray() throws JSONException {
+ try {
+ doTest(ARRAY_ELEMENT_PREFIX, "http://localhost:80/Person\\\\('\\\\w+'\\\\)", CONSTANT_URI_REGEX_EXPECTED_JSON, JSON_STRING_WITH_ARRAY);
+ }
+ catch (AssertionError e) {
+ Assert.assertTrue("Invalid exception message returned: "+ e.getMessage(), e.getMessage().startsWith(ARRAY_ELEMENT_PREFIX + ": Constant expected pattern did not match value"));
+ }
+ }
}
From 668270916f8d781458395ef0cb2ac72f5a02e989 Mon Sep 17 00:00:00 2001
From: Duncan Mackinder
Date: Sun, 19 Jan 2014 16:26:56 +0000
Subject: [PATCH 024/121] Remove minor unwanted code change
---
.../skyscreamer/jsonassert/comparator/CustomComparator.java | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
index af386c5b..95c509bf 100644
--- a/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
+++ b/src/main/java/org/skyscreamer/jsonassert/comparator/CustomComparator.java
@@ -15,12 +15,12 @@ public class CustomComparator extends DefaultComparator {
public CustomComparator(JSONCompareMode mode, Customization... customizations) {
super(mode);
- this.customizations = Arrays.asList((Customization[])customizations);
+ this.customizations = Arrays.asList(customizations);
}
@Override
public void compareValues(String prefix, Object expectedValue, Object actualValue, JSONCompareResult result) throws JSONException {
- Customization customization = getCustomization(prefix);
+ Customization customization = getCustomization(prefix);
if (customization != null) {
try {
if (!customization.matches(prefix, actualValue, expectedValue, result)) {
From 3bb2d5cb6c8e05dfbfdc742fd3956cff6f2bd5ce Mon Sep 17 00:00:00 2001
From: Duncan Mackinder
Date: Sun, 19 Jan 2014 20:34:22 +0000
Subject: [PATCH 025/121] remove unintended indenting change
---
src/main/java/org/skyscreamer/jsonassert/Customization.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/main/java/org/skyscreamer/jsonassert/Customization.java b/src/main/java/org/skyscreamer/jsonassert/Customization.java
index c84dab66..2213ab51 100644
--- a/src/main/java/org/skyscreamer/jsonassert/Customization.java
+++ b/src/main/java/org/skyscreamer/jsonassert/Customization.java
@@ -18,7 +18,7 @@ public static Customization customization(String path, ValueMatcher comp
return new Customization(path, comparator);
}
- public boolean appliesToPath(String path) {
+ public boolean appliesToPath(String path) {
return this.path.equals(path);
}
From 7928d10745ccace6ca5f12b168045a3615becdc6 Mon Sep 17 00:00:00 2001
From: Duncan Mackinder
Date: Mon, 20 Jan 2014 22:37:57 +0000
Subject: [PATCH 026/121] Improve JavaDoc and unit test coverage
Standardise some failure messages, add unit tests for additional cases
and to verify failure descriptions are correct, improve unit test
coverage, add JavaDoc
---
.../jsonassert/ArrayValueMatcher.java | 87 ++++++++++++--
.../jsonassert/LocationAwareValueMatcher.java | 27 ++++-
.../jsonassert/ValueMatcherException.java | 28 ++++-
.../comparator/ArraySizeComparator.java | 79 ++++++++++---
.../comparator/CustomComparator.java | 16 +--
.../jsonassert/ArrayValueMatcherTest.java | 106 ++++++++++++++++--
.../RegularExpressionValueMatcherTest.java | 7 ++
.../comparator/ArraySizeComparatorTest.java | 86 +++++++++++---
8 files changed, 377 insertions(+), 59 deletions(-)
diff --git a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java
index 218c3998..112a36eb 100644
--- a/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java
+++ b/src/main/java/org/skyscreamer/jsonassert/ArrayValueMatcher.java
@@ -7,16 +7,85 @@
import org.skyscreamer.jsonassert.comparator.JSONComparator;
/**
- * A value matcher for arrays. This operates like STRICT_ORDER array match,
+ *
A value matcher for arrays. This operates like STRICT_ORDER array match,
* however if expected array has less elements than actual array the matching
* process loops through the expected array to get expected elements for the
* additional actual elements. In general the expected array will contain a
* single element which is matched against each actual array element in turn.
* This allows simple verification of constant array element components and
* coupled with RegularExpressionValueMatcher can be used to match specific
- * array element components against a regular expression pattern. If the
+ * array element components against a regular expression pattern. As a convenience to reduce syntactic complexity of expected string, if the
* expected object is not an array, a one element expected array is created
- * containing whatever is provided as the expected value.
+ * containing whatever is provided as the expected value.
+ *
+ *
Some examples of typical usage idioms listed below.
+ *
+ *
Assuming JSON to be verified is held in String variable ARRAY_OF_JSONOBJECTS and contains:
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));
+ *
+ *
+ *
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));
+ *
+ *
+ *
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));
+ *
+ *
+ *
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));
+ *
+ *
+ *
Assuming JSON to be verified is held in String variable ARRAY_OF_JSONARRAYS and contains:
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));
+ * 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:
+ *
+ *
+ * Customization innerCustomization = new Customization("a[1]", new ArrayValueMatcher<Object>(comparator, 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));
+ *
+ *
+ *
To simplify complexity of expected JSON string, the value "{a:[[9]]}" may be replaced by "{a:[9]}" or "{a:9}"
*
* @author Duncan Mackinder
*
@@ -44,9 +113,11 @@ public ArrayValueMatcher(JSONComparator comparator) {
*
* @param comparator
* comparator to use to compare elements
+ * @param index
+ * index of the array element to be compared
*/
- public ArrayValueMatcher(JSONComparator comparator, int i) {
- this(comparator, i, i);
+ public ArrayValueMatcher(JSONComparator comparator, int index) {
+ this(comparator, index, index);
}
/**
@@ -56,8 +127,8 @@ public ArrayValueMatcher(JSONComparator comparator, int i) {
*
* @param comparator
* comparator to use to compare elements
- * @from first element in actual array to compare
- * @to last element in actual array to compare
+ * @from first element in actual array to compared
+ * @to last element in actual array to compared
*/
public ArrayValueMatcher(JSONComparator comparator, int from, int to) {
assert comparator != null : "comparator null";
@@ -95,7 +166,7 @@ public boolean equal(String prefix, T actual, T expected, JSONCompareResult resu
Object expectedElement = expectedArray.get((i - first) % expectedLen);
comparator.compareValues(elementPrefix, expectedElement, actualElement, result);
}
- // values must match since no exceptions thrown
+ // any failures have already been passed to result, so return true
return true;
}
catch (JSONException e) {
diff --git a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java
index 879747f2..56653cfa 100644
--- a/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java
+++ b/src/main/java/org/skyscreamer/jsonassert/LocationAwareValueMatcher.java
@@ -11,5 +11,30 @@
*/
public interface LocationAwareValueMatcher extends ValueMatcher {
- boolean equal(String prefix, T actual, T expected, JSONCompareResult result);
+ /**
+ * Match actual value with expected value. If match fails any of the
+ * following may occur, return false, pass failure details to specified
+ * JSONCompareResult and return true, or throw ValueMatcherException
+ * containing failure details. Passing failure details to JSONCompareResult
+ * or returning via ValueMatcherException enables more useful failure
+ * description for cases where expected value depends entirely or in part on
+ * configuration of the ValueMatcher and therefore expected value passed to
+ * this method will not give a useful indication of expected value.
+ *
+ * @param prefix
+ * JSON path of the JSON item being tested
+ * @param actual
+ * JSON value being tested
+ * @param expected
+ * expected JSON value
+ * @param result
+ * JSONCompareResult to which match failure may be passed
+ * @return true if expected and actual equal or any difference has already
+ * been passed to specified result instance, false otherwise.
+ * @throws ValueMatcherException
+ * if expected and actual values not equal and ValueMatcher
+ * needs to override default comparison failure message that
+ * would be generated if this method returned false.
+ */
+ boolean equal(String prefix, T actual, T expected, JSONCompareResult result) throws ValueMatcherException;
}
diff --git a/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java b/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java
index de788cef..3639afce 100644
--- a/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java
+++ b/src/main/java/org/skyscreamer/jsonassert/ValueMatcherException.java
@@ -13,18 +13,34 @@ public class ValueMatcherException extends RuntimeException {
private final String actual;
+ /**
+ * Create new ValueMatcherException
+ *
+ * @param message
+ * description of exception
+ * @param expected
+ * value expected by ValueMatcher
+ * @param actual
+ * value being tested by ValueMatcher
+ */
public ValueMatcherException(String message, String expected, String actual) {
super(message);
this.expected = expected;
this.actual = actual;
}
-
- public ValueMatcherException(Throwable cause, String expected, String actual) {
- super(cause);
- this.expected = expected;
- this.actual = actual;
- }
+ /**
+ * Create new ValueMatcherException
+ *
+ * @param message
+ * description of exception
+ * @param cause
+ * cause of ValueMatcherException
+ * @param expected
+ * value expected by ValueMatcher
+ * @param actual
+ * value being tested by ValueMatcher
+ */
public ValueMatcherException(String message, Throwable cause, String expected, String actual) {
super(message, cause);
this.expected = expected;
diff --git a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java
index 86eb50a6..e426cb8e 100644
--- a/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java
+++ b/src/main/java/org/skyscreamer/jsonassert/comparator/ArraySizeComparator.java
@@ -1,53 +1,106 @@
package org.skyscreamer.jsonassert.comparator;
+import java.text.MessageFormat;
+
import org.json.JSONArray;
import org.json.JSONException;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.skyscreamer.jsonassert.JSONCompareResult;
/**
- * A JSONAssert array size comparator. Expected array should consist of either 1
- * or 2 integer values that define maximum and minimum size of that the actual
- * array is expected to be. If expected array contains a single integer value
- * then the actual array must contain exactly that number of elements.
+ * A JSONAssert array size comparator.
+ *
+ *
Some typical usage idioms are listed below.
+ *
+ *
Assuming JSON to be verified is held in String variable ARRAY_OF_JSONOBJECTS and contains:
<dependency> <groupId>org.skyscreamer</groupId> <artifactId>jsonassert</artifactId>
- <version>1.2.2</version>
+ <version>1.2.3</version> </dependency>
From ff00741499f0a8e94af9204a8d73760bd72968c8 Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 05:52:54 -0500
Subject: [PATCH 029/121] [maven-release-plugin] prepare release
jsonassert-1.2.3
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 13afc2ee..c0fb7fad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.3-SNAPSHOT
+ 1.2.3jarJSONassert
From 3eb97c44af682066333499d2184ec93a11ef04b3 Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 05:52:57 -0500
Subject: [PATCH 030/121] [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 c0fb7fad..b6cc06d4 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.3
+ 1.2.4-SNAPSHOTjarJSONassert
From da8983b93ac764e79f93daba80056798fa0d36a4 Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 05:58:49 -0500
Subject: [PATCH 031/121] Revert "[maven-release-plugin] prepare for next
development iteration"
This reverts commit 3eb97c44af682066333499d2184ec93a11ef04b3.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index b6cc06d4..c0fb7fad 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.4-SNAPSHOT
+ 1.2.3jarJSONassert
From e9faddae006c0862fda39552eea5d3a76874e75a Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 05:59:05 -0500
Subject: [PATCH 032/121] Revert "[maven-release-plugin] prepare release
jsonassert-1.2.3"
This reverts commit ff00741499f0a8e94af9204a8d73760bd72968c8.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index c0fb7fad..13afc2ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.3
+ 1.2.3-SNAPSHOTjarJSONassert
From f64fb7f6be66e319780bb8fcc28006ea5f32773a Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 05:59:33 -0500
Subject: [PATCH 033/121] Updated maven plugin version to fix release process
bug
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 13afc2ee..09621a71 100644
--- a/pom.xml
+++ b/pom.xml
@@ -76,7 +76,7 @@
org.apache.maven.pluginsmaven-site-plugin
- 3.1
+ 3.3
From 798eb7104cd14aec2b492a07783d7088acecc65a Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 06:01:54 -0500
Subject: [PATCH 034/121] [maven-release-plugin] prepare release
jsonassert-1.2.3
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 09621a71..bfc376c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.3-SNAPSHOT
+ 1.2.3jarJSONassert
From a1b8cb076943fb488a068e6ce5269b47636a2bba Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 06:03:09 -0500
Subject: [PATCH 035/121] Revert "[maven-release-plugin] prepare release
jsonassert-1.2.3"
This reverts commit 798eb7104cd14aec2b492a07783d7088acecc65a.
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index bfc376c7..09621a71 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.3
+ 1.2.3-SNAPSHOTjarJSONassert
From 2b42029063f69188bff298cd4dad863f338be90f Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 06:05:35 -0500
Subject: [PATCH 036/121] [maven-release-plugin] prepare release
jsonassert-1.2.3
---
pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pom.xml b/pom.xml
index 09621a71..bfc376c7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.3-SNAPSHOT
+ 1.2.3jarJSONassert
From ce4eebf7a44ea8af83f1dd6d869c8369d77f5263 Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Wed, 5 Feb 2014 06:05:38 -0500
Subject: [PATCH 037/121] [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 bfc376c7..50dc2183 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
org.skyscreamerjsonassert
- 1.2.3
+ 1.2.4-SNAPSHOTjarJSONassert
From 78e30a08621d83aea3e3f0a6023a565478744135 Mon Sep 17 00:00:00 2001
From: Duncan Mackinder
Date: Tue, 11 Feb 2014 17:00:10 +0000
Subject: [PATCH 038/121] 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 039/121] 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 @@
JSONassertA 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 040/121] 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 041/121] 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 042/121] 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 043/121] 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 044/121] 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 045/121] 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 046/121] 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 047/121] 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.skyscreamerjsonassert
- 1.2.3
+ 1.3.0test
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 @@
<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 054/121] [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.skyscreamerjsonassert
- 1.4.0-SNAPSHOT
+ 1.4.0jarJSONassert
From 3c2da7ae14ba0987ef021139bb8f0e9ff08ce9d2 Mon Sep 17 00:00:00 2001
From: Carter Page
Date: Sun, 30 Oct 2016 17:11:49 -0400
Subject: [PATCH 055/121] [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.skyscreamerjsonassert
- 1.4.0
+ 1.4.1-SNAPSHOTjarJSONassert
From 472f6cccb3ab00e949895733dd2b956ff9d02912 Mon Sep 17 00:00:00 2001
From: gil
Date: Mon, 31 Oct 2016 11:15:56 +0100
Subject: [PATCH 056/121] 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 057/121] 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 058/121] 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.