From becc1631e6dbe41e3a0245d765b01509de2608b5 Mon Sep 17 00:00:00 2001 From: simonh5 Date: Mon, 18 Sep 2023 20:20:13 -0500 Subject: [PATCH 1/4] fix: flakiness in JSONMLTest#testToJSONObject_reversibility --- build.gradle | 1 + pom.xml | 7 +++++++ src/test/java/org/json/junit/JSONMLTest.java | 3 ++- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 8a3708a..5a5be37 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ dependencies { testImplementation 'junit:junit:4.13.1' testImplementation 'com.jayway.jsonpath:json-path:2.1.0' testImplementation 'org.mockito:mockito-core:4.2.0' + testImplementation 'org.skyscreamer:jsonassert:1.5.1' } subprojects { diff --git a/pom.xml b/pom.xml index 720529c..8bbcc3c 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,13 @@ 4.2.0 test + + + org.skyscreamer + jsonassert + 1.5.1 + test + diff --git a/src/test/java/org/json/junit/JSONMLTest.java b/src/test/java/org/json/junit/JSONMLTest.java index 35c0af2..9b5e5b6 100644 --- a/src/test/java/org/json/junit/JSONMLTest.java +++ b/src/test/java/org/json/junit/JSONMLTest.java @@ -8,6 +8,7 @@ import static org.junit.Assert.*; import org.json.*; import org.junit.Test; +import org.skyscreamer.jsonassert.JSONAssert; /** * Tests for org.json.JSONML.java @@ -763,7 +764,7 @@ public class JSONMLTest { final JSONObject revertedObject = JSONML.toJSONObject(xml, false); final String newJson = revertedObject.toString(); assertTrue("JSON Objects are not similar",originalObject.similar(revertedObject)); - assertEquals("original JSON does not equal the new JSON",originalJson, newJson); + JSONAssert.assertEquals("original JSON does not equal the new JSON", originalJson, newJson, false); } // these tests do not pass for the following reasons: From ca88454f1cdaedf46bcce546c0a9ce79709c544c Mon Sep 17 00:00:00 2001 From: simonh5 Date: Tue, 19 Sep 2023 14:28:06 -0500 Subject: [PATCH 2/4] fix: flakiness in org.json.junit.JSONObjectTest#valueToString --- build.gradle | 1 + pom.xml | 7 +++++++ src/test/java/org/json/junit/JSONObjectTest.java | 9 +++++---- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index 8a3708a..5a5be37 100644 --- a/build.gradle +++ b/build.gradle @@ -23,6 +23,7 @@ dependencies { testImplementation 'junit:junit:4.13.1' testImplementation 'com.jayway.jsonpath:json-path:2.1.0' testImplementation 'org.mockito:mockito-core:4.2.0' + testImplementation 'org.skyscreamer:jsonassert:1.5.1' } subprojects { diff --git a/pom.xml b/pom.xml index 720529c..8bbcc3c 100644 --- a/pom.xml +++ b/pom.xml @@ -72,6 +72,13 @@ 4.2.0 test + + + org.skyscreamer + jsonassert + 1.5.1 + test + diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 2de8f81..4eefea8 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -57,6 +57,7 @@ import org.junit.Test; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.JsonPath; +import org.skyscreamer.jsonassert.JSONAssert; /** * JSONObject, along with JSONArray, are the central classes of the reference app. @@ -2025,8 +2026,8 @@ public class JSONObjectTest { "\"key3\":\"val3\""+ "}"; JSONObject jsonObject = new JSONObject(jsonObjectStr); - assertTrue("jsonObject valueToString() incorrect", - JSONObject.valueToString(jsonObject).equals(jsonObject.toString())); + JSONAssert.assertEquals("jsonObject valueToString() incorrect", + JSONObject.valueToString(jsonObject), jsonObject.toString(), false); String jsonArrayStr = "[1,2,3]"; JSONArray jsonArray = new JSONArray(jsonArrayStr); @@ -2036,8 +2037,8 @@ public class JSONObjectTest { map.put("key1", "val1"); map.put("key2", "val2"); map.put("key3", "val3"); - assertTrue("map valueToString() incorrect", - jsonObject.toString().equals(JSONObject.valueToString(map))); + JSONAssert.assertEquals("map valueToString() incorrect", + jsonObject.toString(), JSONObject.valueToString(map), false); Collection collection = new ArrayList(); collection.add(Integer.valueOf(1)); collection.add(Integer.valueOf(2)); From e4aa7f1308722b1283fc828dcb2326915a5d29da Mon Sep 17 00:00:00 2001 From: simonh5 Date: Thu, 12 Oct 2023 21:09:27 -0500 Subject: [PATCH 3/4] fix: change from JSONAssert to checking the similarity of JSONObjects --- src/test/java/org/json/junit/JSONMLTest.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/test/java/org/json/junit/JSONMLTest.java b/src/test/java/org/json/junit/JSONMLTest.java index 9b5e5b6..4d36498 100644 --- a/src/test/java/org/json/junit/JSONMLTest.java +++ b/src/test/java/org/json/junit/JSONMLTest.java @@ -8,7 +8,6 @@ import static org.junit.Assert.*; import org.json.*; import org.junit.Test; -import org.skyscreamer.jsonassert.JSONAssert; /** * Tests for org.json.JSONML.java @@ -763,8 +762,7 @@ public class JSONMLTest { final String xml = JSONML.toString(originalObject); final JSONObject revertedObject = JSONML.toJSONObject(xml, false); final String newJson = revertedObject.toString(); - assertTrue("JSON Objects are not similar",originalObject.similar(revertedObject)); - JSONAssert.assertEquals("original JSON does not equal the new JSON", originalJson, newJson, false); + assertTrue("original JSON does not equal the new JSON", originalObject.similar(revertedObject)); } // these tests do not pass for the following reasons: From 29a7f4622d887a90e15d719f88fad770b523ed69 Mon Sep 17 00:00:00 2001 From: simonh5 Date: Fri, 13 Oct 2023 20:58:50 -0500 Subject: [PATCH 4/4] remove JSONAssert --- build.gradle | 1 - pom.xml | 7 ------- src/test/java/org/json/junit/JSONMLTest.java | 3 ++- src/test/java/org/json/junit/JSONObjectTest.java | 12 +++++++----- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 5a5be37..8a3708a 100644 --- a/build.gradle +++ b/build.gradle @@ -23,7 +23,6 @@ dependencies { testImplementation 'junit:junit:4.13.1' testImplementation 'com.jayway.jsonpath:json-path:2.1.0' testImplementation 'org.mockito:mockito-core:4.2.0' - testImplementation 'org.skyscreamer:jsonassert:1.5.1' } subprojects { diff --git a/pom.xml b/pom.xml index 8bbcc3c..720529c 100644 --- a/pom.xml +++ b/pom.xml @@ -72,13 +72,6 @@ 4.2.0 test - - - org.skyscreamer - jsonassert - 1.5.1 - test - diff --git a/src/test/java/org/json/junit/JSONMLTest.java b/src/test/java/org/json/junit/JSONMLTest.java index 4d36498..154af64 100644 --- a/src/test/java/org/json/junit/JSONMLTest.java +++ b/src/test/java/org/json/junit/JSONMLTest.java @@ -762,7 +762,8 @@ public class JSONMLTest { final String xml = JSONML.toString(originalObject); final JSONObject revertedObject = JSONML.toJSONObject(xml, false); final String newJson = revertedObject.toString(); - assertTrue("original JSON does not equal the new JSON", originalObject.similar(revertedObject)); + assertTrue("JSON Objects are not similar", originalObject.similar(revertedObject)); + assertTrue("JSON Strings are not similar", new JSONObject(originalJson).similar(new JSONObject(newJson))); } // these tests do not pass for the following reasons: diff --git a/src/test/java/org/json/junit/JSONObjectTest.java b/src/test/java/org/json/junit/JSONObjectTest.java index 4eefea8..ac9a287 100644 --- a/src/test/java/org/json/junit/JSONObjectTest.java +++ b/src/test/java/org/json/junit/JSONObjectTest.java @@ -57,7 +57,6 @@ import org.junit.Test; import com.jayway.jsonpath.Configuration; import com.jayway.jsonpath.JsonPath; -import org.skyscreamer.jsonassert.JSONAssert; /** * JSONObject, along with JSONArray, are the central classes of the reference app. @@ -2026,8 +2025,10 @@ public class JSONObjectTest { "\"key3\":\"val3\""+ "}"; JSONObject jsonObject = new JSONObject(jsonObjectStr); - JSONAssert.assertEquals("jsonObject valueToString() incorrect", - JSONObject.valueToString(jsonObject), jsonObject.toString(), false); + assertTrue("jsonObject valueToString() incorrect", + new JSONObject(JSONObject.valueToString(jsonObject)) + .similar(new JSONObject(jsonObject.toString())) + ); String jsonArrayStr = "[1,2,3]"; JSONArray jsonArray = new JSONArray(jsonArrayStr); @@ -2037,8 +2038,9 @@ public class JSONObjectTest { map.put("key1", "val1"); map.put("key2", "val2"); map.put("key3", "val3"); - JSONAssert.assertEquals("map valueToString() incorrect", - jsonObject.toString(), JSONObject.valueToString(map), false); + assertTrue("map valueToString() incorrect", + new JSONObject(jsonObject.toString()) + .similar(new JSONObject(JSONObject.valueToString(map)))); Collection collection = new ArrayList(); collection.add(Integer.valueOf(1)); collection.add(Integer.valueOf(2));