diff --git a/src/test/java/com/unitvectory/jsonassertify/ArrayValueMatcherTest.java b/src/test/java/com/unitvectory/jsonassertify/ArrayValueMatcherTest.java index 88c6aa8..f0fe1c9 100644 --- a/src/test/java/com/unitvectory/jsonassertify/ArrayValueMatcherTest.java +++ b/src/test/java/com/unitvectory/jsonassertify/ArrayValueMatcherTest.java @@ -14,6 +14,7 @@ package com.unitvectory.jsonassertify; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -306,4 +307,12 @@ public void verifySecondElementOfArrayIsJSONArrayWhoseFirstElementIs9WithEvenMor JSONAssert.assertEquals("{a:9}", ARRAY_OF_JSONARRAYS, new CustomComparator(JSONCompareMode.LENIENT, customization)); } + + @Test + public void testEqualMethodReturnsFalse() { + ArrayValueMatcher matcher = new ArrayValueMatcher<>(comparator); + // The non-location-aware equal() method always returns false by design; + // use the LocationAwareValueMatcher.equal() method for actual comparisons. + assertFalse(matcher.equal("value1", "value2")); + } } diff --git a/src/test/java/com/unitvectory/jsonassertify/CustomizationTest.java b/src/test/java/com/unitvectory/jsonassertify/CustomizationTest.java new file mode 100644 index 0000000..bc164fe --- /dev/null +++ b/src/test/java/com/unitvectory/jsonassertify/CustomizationTest.java @@ -0,0 +1,97 @@ +/* + * 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 com.unitvectory.jsonassertify; + +import static org.junit.jupiter.api.Assertions.*; + +import org.json.JSONException; +import org.junit.jupiter.api.Test; + +/** + * Unit tests for {@link Customization} + */ +public class CustomizationTest { + + @Test + public void testStaticFactoryMethod() { + ValueMatcher matcher = (o1, o2) -> true; + Customization customization = Customization.customization("path.to.field", matcher); + assertNotNull(customization); + assertTrue(customization.appliesToPath("path.to.field")); + } + + @Test + public void testAppliesToPathExactMatch() { + ValueMatcher matcher = (o1, o2) -> true; + Customization customization = new Customization("user.name", matcher); + assertTrue(customization.appliesToPath("user.name")); + assertFalse(customization.appliesToPath("user.id")); + } + + @Test + public void testAppliesToPathWithSingleWildcard() { + ValueMatcher matcher = (o1, o2) -> true; + Customization customization = new Customization("user.*.name", matcher); + assertTrue(customization.appliesToPath("user.profile.name")); + assertTrue(customization.appliesToPath("user.account.name")); + assertFalse(customization.appliesToPath("user.profile.id")); + } + + @Test + public void testAppliesToPathWithDoubleWildcard() { + ValueMatcher matcher = (o1, o2) -> true; + Customization customization = new Customization("user.**.name", matcher); + assertTrue(customization.appliesToPath("user.name")); + assertTrue(customization.appliesToPath("user.profile.name")); + assertTrue(customization.appliesToPath("user.profile.details.name")); + } + + @Test + public void testAppliesToPathWithRootDoubleWildcard() { + ValueMatcher matcher = (o1, o2) -> true; + Customization customization = new Customization("**.name", matcher); + assertTrue(customization.appliesToPath("name")); + assertTrue(customization.appliesToPath("user.name")); + assertTrue(customization.appliesToPath("user.profile.name")); + } + + @Test + public void testMatchesWithLocationAwareValueMatcher() throws JSONException { + LocationAwareValueMatcher matcher = new LocationAwareValueMatcher() { + @Override + public boolean equal(Object o1, Object o2) { + return o1.equals(o2); + } + + @Override + public boolean equal(String prefix, Object actual, Object expected, JSONCompareResult result) { + return actual.equals(expected); + } + }; + + Customization customization = new Customization("test", matcher); + JSONCompareResult result = new JSONCompareResult(); + assertTrue(customization.matches("test", "value", "value", result)); + assertFalse(customization.matches("test", "value1", "value2", result)); + } + + @Test + public void testMatchesWithRegularValueMatcher() throws JSONException { + ValueMatcher matcher = (o1, o2) -> o1.equals(o2); + Customization customization = new Customization("test", matcher); + JSONCompareResult result = new JSONCompareResult(); + assertTrue(customization.matches("test", "value", "value", result)); + assertFalse(customization.matches("test", "value1", "value2", result)); + } +} diff --git a/src/test/java/com/unitvectory/jsonassertify/JSONAssertTest.java b/src/test/java/com/unitvectory/jsonassertify/JSONAssertTest.java index 110637d..1768e47 100644 --- a/src/test/java/com/unitvectory/jsonassertify/JSONAssertTest.java +++ b/src/test/java/com/unitvectory/jsonassertify/JSONAssertTest.java @@ -876,4 +876,199 @@ private void verifyErrorMessage(String message, AssertionError ae) { assertTrue(ae.getMessage().contains(message)); assertTrue(ae.getMessage().startsWith(message)); } + + // ===== Type mismatch tests ===== + + @Test + public void testAssertEqualsExpectingArrayButPassingObject() throws JSONException { + JSONObject actual = new JSONObject(); + actual.put("id", 1); + // Passing an array expected string but a JSONObject actual should throw + assertThrows(AssertionError.class, () -> + JSONAssert.assertEquals("[1,2,3]", actual, LENIENT)); + } + + @Test + public void testAssertEqualsExpectingArrayButPassingObjectWithMessage() throws JSONException { + JSONObject actual = new JSONObject(); + actual.put("id", 1); + assertThrows(AssertionError.class, () -> + JSONAssert.assertEquals("Custom message", "[1,2,3]", actual, LENIENT)); + } + + @Test + public void testAssertNotEqualsExpectingArrayButPassingObject() throws JSONException { + JSONObject actual = new JSONObject(); + actual.put("id", 1); + assertThrows(AssertionError.class, () -> + JSONAssert.assertNotEquals("[1,2,3]", actual, LENIENT)); + } + + @Test + public void testAssertNotEqualsExpectingArrayButPassingObjectWithMessage() throws JSONException { + JSONObject actual = new JSONObject(); + actual.put("id", 1); + assertThrows(AssertionError.class, () -> + JSONAssert.assertNotEquals("Custom message", "[1,2,3]", actual, LENIENT)); + } + + @Test + public void testAssertEqualsExpectingObjectButPassingArray() throws JSONException { + JSONArray actual = new JSONArray(); + actual.put(1); + actual.put(2); + assertThrows(AssertionError.class, () -> + JSONAssert.assertEquals("{id:1}", actual, LENIENT)); + } + + @Test + public void testAssertNotEqualsExpectingObjectButPassingArray() throws JSONException { + JSONArray actual = new JSONArray(); + actual.put(1); + actual.put(2); + assertThrows(AssertionError.class, () -> + JSONAssert.assertNotEquals("{id:1}", actual, LENIENT)); + } + + @Test + public void testAssertNotEqualsExpectingObjectButPassingArrayWithMessage() throws JSONException { + JSONArray actual = new JSONArray(); + actual.put(1); + actual.put(2); + assertThrows(AssertionError.class, () -> + JSONAssert.assertNotEquals("Message", "{id:1}", actual, LENIENT)); + } + + // ===== Null string tests ===== + + @Test + public void testAssertEqualsStringNullExpected() throws JSONException { + assertThrows(AssertionError.class, () -> + JSONAssert.assertEquals(null, "{id:1}", LENIENT)); + } + + @Test + public void testAssertEqualsStringNullActual() throws JSONException { + assertThrows(AssertionError.class, () -> + JSONAssert.assertEquals("{id:1}", (String) null, LENIENT)); + } + + // ===== Comparator-based assertion tests ===== + + @Test + public void testAssertNotEqualsWithComparator() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + JSONAssert.assertNotEquals("{id:1}", "{id:2}", comparator); + } + + @Test + public void testAssertNotEqualsWithComparatorAndMessage() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + JSONAssert.assertNotEquals("Message", "{id:1}", "{id:2}", comparator); + } + + @Test + public void testAssertNotEqualsWithComparatorFailsWhenEqual() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + assertThrows(AssertionError.class, () -> + JSONAssert.assertNotEquals("{id:1}", "{id:1}", comparator)); + } + + @Test + public void testAssertNotEqualsWithComparatorAndMessageFailsWhenEqual() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + assertThrows(AssertionError.class, () -> + JSONAssert.assertNotEquals("Message", "{id:1}", "{id:1}", comparator)); + } + + @Test + public void testAssertEqualsJSONObjectWithComparator() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", 1); + actual.put("id", 1); + JSONAssert.assertEquals(expected, actual, comparator); + } + + @Test + public void testAssertEqualsJSONObjectWithComparatorAndMessage() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", 1); + actual.put("id", 1); + JSONAssert.assertEquals("Message", expected, actual, comparator); + } + + @Test + public void testAssertEqualsJSONObjectWithComparatorFails() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", 1); + actual.put("id", 2); + assertThrows(AssertionError.class, () -> + JSONAssert.assertEquals(expected, actual, comparator)); + } + + @Test + public void testAssertNotEqualsJSONObjectWithComparator() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", 1); + actual.put("id", 2); + JSONAssert.assertNotEquals(expected, actual, comparator); + } + + @Test + public void testAssertNotEqualsJSONObjectWithComparatorAndMessage() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", 1); + actual.put("id", 2); + JSONAssert.assertNotEquals("Message", expected, actual, comparator); + } + + @Test + public void testAssertNotEqualsJSONObjectWithComparatorFails() throws JSONException { + JSONComparator comparator = new com.unitvectory.jsonassertify.comparator.DefaultComparator(LENIENT); + JSONObject expected = new JSONObject(); + JSONObject actual = new JSONObject(); + expected.put("id", 1); + actual.put("id", 1); + assertThrows(AssertionError.class, () -> + JSONAssert.assertNotEquals(expected, actual, comparator)); + } + + @Test + public void testAssertEqualsJSONArrayWithCompareMode() throws JSONException { + JSONArray expected = new JSONArray(); + JSONArray actual = new JSONArray(); + expected.put(1); + expected.put(2); + actual.put(1); + actual.put(2); + JSONAssert.assertEquals(expected, actual, LENIENT); + } + + @Test + public void testAssertEqualsJSONArrayWithCompareModeFails() throws JSONException { + JSONArray expected = new JSONArray(); + JSONArray actual = new JSONArray(); + expected.put(1); + expected.put(2); + actual.put(1); + actual.put(3); + assertThrows(AssertionError.class, () -> + JSONAssert.assertEquals(expected, actual, LENIENT)); + } + + @Test + public void testAssertEqualsSameStringReference() throws JSONException { + String json = "{id:1}"; + JSONAssert.assertEquals(json, json, LENIENT); + } } diff --git a/src/test/java/com/unitvectory/jsonassertify/JSONCompareResultTest.java b/src/test/java/com/unitvectory/jsonassertify/JSONCompareResultTest.java new file mode 100644 index 0000000..91a6b1e --- /dev/null +++ b/src/test/java/com/unitvectory/jsonassertify/JSONCompareResultTest.java @@ -0,0 +1,127 @@ +/* + * 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 com.unitvectory.jsonassertify; + +import static org.junit.jupiter.api.Assertions.*; + +import org.json.JSONException; +import org.junit.jupiter.api.Test; + +/** + * Unit tests for {@link JSONCompareResult} + */ +public class JSONCompareResultTest { + + @Test + public void testToStringWithFailure() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:2}", JSONCompareMode.STRICT); + assertTrue(result.failed()); + String message = result.toString(); + assertTrue(message.contains("Expected")); + assertTrue(message.contains("got")); + } + + @Test + public void testToStringWhenPassed() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:1}", JSONCompareMode.STRICT); + assertTrue(result.passed()); + // toString on passed result should return empty message + String message = result.toString(); + assertEquals("", message); + } + + @Test + public void testIsFailureOnFieldTrue() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:2}", JSONCompareMode.STRICT); + assertTrue(result.failed()); + assertTrue(result.isFailureOnField()); + } + + @Test + public void testIsFailureOnFieldFalse() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:1}", JSONCompareMode.STRICT); + assertTrue(result.passed()); + assertFalse(result.isFailureOnField()); + } + + @Test + public void testIsMissingOnFieldTrue() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1, name:\"Joe\"}", "{id:1}", JSONCompareMode.STRICT); + assertTrue(result.failed()); + assertTrue(result.isMissingOnField()); + } + + @Test + public void testIsMissingOnFieldFalse() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:1}", JSONCompareMode.STRICT); + assertTrue(result.passed()); + assertFalse(result.isMissingOnField()); + } + + @Test + public void testIsUnexpectedOnFieldTrue() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:1, name:\"Joe\"}", JSONCompareMode.NON_EXTENSIBLE); + assertTrue(result.failed()); + assertTrue(result.isUnexpectedOnField()); + } + + @Test + public void testIsUnexpectedOnFieldFalse() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:1}", JSONCompareMode.STRICT); + assertTrue(result.passed()); + assertFalse(result.isUnexpectedOnField()); + } + + @Test + public void testGetFieldFailures() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:2}", JSONCompareMode.STRICT); + assertTrue(result.failed()); + assertEquals(1, result.getFieldFailures().size()); + assertEquals("id", result.getFieldFailures().get(0).getField()); + } + + @Test + public void testGetFieldMissing() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1, name:\"Joe\"}", "{id:1}", JSONCompareMode.STRICT); + assertTrue(result.failed()); + assertEquals(1, result.getFieldMissing().size()); + } + + @Test + public void testGetFieldUnexpected() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:1, name:\"Joe\"}", JSONCompareMode.NON_EXTENSIBLE); + assertTrue(result.failed()); + assertEquals(1, result.getFieldUnexpected().size()); + } + + @Test + public void testGetMessage() throws JSONException { + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:2}", JSONCompareMode.STRICT); + assertTrue(result.failed()); + String message = result.getMessage(); + assertNotNull(message); + assertTrue(message.length() > 0); + } + + @Test + public void testPassedAndFailed() throws JSONException { + JSONCompareResult passedResult = JSONCompare.compareJSON("{id:1}", "{id:1}", JSONCompareMode.STRICT); + assertTrue(passedResult.passed()); + assertFalse(passedResult.failed()); + + JSONCompareResult failedResult = JSONCompare.compareJSON("{id:1}", "{id:2}", JSONCompareMode.STRICT); + assertFalse(failedResult.passed()); + assertTrue(failedResult.failed()); + } +} diff --git a/src/test/java/com/unitvectory/jsonassertify/JSONCompareTest.java b/src/test/java/com/unitvectory/jsonassertify/JSONCompareTest.java index 9013b4f..0d96583 100644 --- a/src/test/java/com/unitvectory/jsonassertify/JSONCompareTest.java +++ b/src/test/java/com/unitvectory/jsonassertify/JSONCompareTest.java @@ -182,4 +182,13 @@ public boolean matchesSafely(JSONCompareResult item) { } }; } + + @Test + public void succeedsWithNestedArraysInLenientMode() throws JSONException { + // Test case with nested arrays where order doesn't matter (LENIENT) + assertTrue(compareJSON( + "{arr:[[1,2],[3,4]]}", + "{arr:[[3,4],[1,2]]}", + LENIENT).passed()); + } } diff --git a/src/test/java/com/unitvectory/jsonassertify/JSONParserTest.java b/src/test/java/com/unitvectory/jsonassertify/JSONParserTest.java new file mode 100644 index 0000000..2b1f134 --- /dev/null +++ b/src/test/java/com/unitvectory/jsonassertify/JSONParserTest.java @@ -0,0 +1,102 @@ +/* + * 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 com.unitvectory.jsonassertify; + +import static org.junit.jupiter.api.Assertions.*; + +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; +import org.json.JSONString; +import org.junit.jupiter.api.Test; + +/** + * Unit tests for {@link JSONParser} + */ +public class JSONParserTest { + + @Test + public void testParseJSONObject() throws JSONException { + Object result = JSONParser.parseJSON("{id:1}"); + assertTrue(result instanceof JSONObject); + } + + @Test + public void testParseJSONArray() throws JSONException { + Object result = JSONParser.parseJSON("[1,2,3]"); + assertTrue(result instanceof JSONArray); + } + + @Test + public void testParseJSONString() throws JSONException { + Object result = JSONParser.parseJSON("\"hello\""); + assertTrue(result instanceof JSONString); + } + + @Test + public void testParseJSONNumber() throws JSONException { + Object result = JSONParser.parseJSON("123"); + assertTrue(result instanceof JSONString); + } + + @Test + public void testParseJSONNegativeNumber() throws JSONException { + Object result = JSONParser.parseJSON("-123"); + assertTrue(result instanceof JSONString); + } + + @Test + public void testParseJSONDecimalNumber() throws JSONException { + Object result = JSONParser.parseJSON("123.456"); + assertTrue(result instanceof JSONString); + } + + @Test + public void testParseJSONScientificNotation() throws JSONException { + Object result = JSONParser.parseJSON("1.5e10"); + assertTrue(result instanceof JSONString); + } + + @Test + public void testParseJSONUnparsableString() { + assertThrows(JSONException.class, () -> + JSONParser.parseJSON("invalid json")); + } + + @Test + public void testParseJSONEmptyString() { + assertThrows(JSONException.class, () -> + JSONParser.parseJSON("")); + } + + @Test + public void testParseJSONWhitespaceOnly() { + // Test whitespace-only input, which is different from empty string + // as it tests the trim() behavior in the parser + assertThrows(JSONException.class, () -> + JSONParser.parseJSON(" ")); + } + + @Test + public void testParseJSONWithLeadingWhitespace() throws JSONException { + Object result = JSONParser.parseJSON(" {id:1}"); + assertTrue(result instanceof JSONObject); + } + + @Test + public void testParseJSONWithTrailingWhitespace() throws JSONException { + Object result = JSONParser.parseJSON("{id:1} "); + assertTrue(result instanceof JSONObject); + } +} diff --git a/src/test/java/com/unitvectory/jsonassertify/comparator/CustomComparatorTest.java b/src/test/java/com/unitvectory/jsonassertify/comparator/CustomComparatorTest.java index 8714184..3109cdb 100644 --- a/src/test/java/com/unitvectory/jsonassertify/comparator/CustomComparatorTest.java +++ b/src/test/java/com/unitvectory/jsonassertify/comparator/CustomComparatorTest.java @@ -18,9 +18,11 @@ import org.json.JSONArray; import org.json.JSONException; import org.junit.jupiter.api.Test; +import com.unitvectory.jsonassertify.Customization; import com.unitvectory.jsonassertify.JSONCompare; import com.unitvectory.jsonassertify.JSONCompareMode; import com.unitvectory.jsonassertify.JSONCompareResult; +import com.unitvectory.jsonassertify.ValueMatcher; /** * @author Ivan Zaytsev @@ -52,4 +54,14 @@ public void testFullArrayComparison() throws Exception { String message = compareResult.getMessage().replaceAll("\n", ""); assertTrue(message.matches(".*id=5.*Expected.*id=6.*Unexpected.*id=7.*Unexpected.*"), message); } + + @Test + public void testWithFailingMatcher() throws JSONException { + ValueMatcher matcher = (o1, o2) -> false; + Customization customization = new Customization("id", matcher); + CustomComparator comparator = new CustomComparator(JSONCompareMode.STRICT, customization); + + JSONCompareResult result = JSONCompare.compareJSON("{id:1}", "{id:1}", comparator); + assertTrue(result.failed()); + } } diff --git a/src/test/java/com/unitvectory/jsonassertify/comparator/JSONCompareUtilTest.java b/src/test/java/com/unitvectory/jsonassertify/comparator/JSONCompareUtilTest.java index 2537e9e..cdeed5b 100644 --- a/src/test/java/com/unitvectory/jsonassertify/comparator/JSONCompareUtilTest.java +++ b/src/test/java/com/unitvectory/jsonassertify/comparator/JSONCompareUtilTest.java @@ -13,10 +13,13 @@ */ package com.unitvectory.jsonassertify.comparator; +import org.json.JSONArray; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.Collections; @@ -59,4 +62,20 @@ public void testGetCardinalityMap() { assertEquals(NUM_D, cardinalityMap.get("D").intValue()); assertEquals(NUM_E, cardinalityMap.get("E").intValue()); } + + @Test + public void testAllJSONArraysTrue() throws Exception { + JSONArray array = new JSONArray(); + array.put(new JSONArray("[1,2]")); + array.put(new JSONArray("[3,4]")); + assertTrue(JSONCompareUtil.allJSONArrays(array)); + } + + @Test + public void testAllJSONArraysFalse() throws Exception { + JSONArray array = new JSONArray(); + array.put(new JSONArray("[1,2]")); + array.put("not an array"); + assertFalse(JSONCompareUtil.allJSONArrays(array)); + } }