From fe45fa9cfbaf1a4b4df223ff3357a0d73d3a2932 Mon Sep 17 00:00:00 2001 From: Allon Mureinik Date: Thu, 5 Oct 2023 15:29:51 +0300 Subject: [PATCH 1/2] Fix XMLTest on Windows XMLTest.testIndentComplicatedJsonObjectWithArrayAndWithConfig fails when run on Windows due to mismatching linebreaks (that aren't important for the test's functionality) between the actual and expected strings. For the actual strings, linebreaks are canonized to the platform's native linebreak using `replaceAll("\\n|\\r\\n", System.getProperty("line.separator")`. However, the expected result is read from a file, and is left with the linebreaks that were originally used to create it. The solution is to perform the same canonization on both strings. Closes #781 --- src/test/java/org/json/junit/XMLTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/java/org/json/junit/XMLTest.java b/src/test/java/org/json/junit/XMLTest.java index e940032..6e7b1a9 100644 --- a/src/test/java/org/json/junit/XMLTest.java +++ b/src/test/java/org/json/junit/XMLTest.java @@ -1239,7 +1239,8 @@ public class XMLTest { for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) { expected.append(buffer, 0, numRead); } - assertEquals(expected.toString(), actualString.replaceAll("\\n|\\r\\n", System.getProperty("line.separator"))); + assertEquals(expected.toString().replaceAll("\\n|\\r\\n", System.getProperty("line.separator")), + actualString.replaceAll("\\n|\\r\\n", System.getProperty("line.separator"))); } finally { if (xmlStream != null) { xmlStream.close(); From 4c8cac22a89069209439809243ac4eddf6b0dd47 Mon Sep 17 00:00:00 2001 From: Allon Mureinik Date: Thu, 5 Oct 2023 19:47:33 +0300 Subject: [PATCH 2/2] Use System.lineSeparator() Use the built-in System.lineSeparator() instead of implementing it ourselves with System.getProperty("line.separator") in order to clean up the code and make it easier to maintain. --- src/test/java/org/json/junit/XMLTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/json/junit/XMLTest.java b/src/test/java/org/json/junit/XMLTest.java index 6e7b1a9..712b8ee 100644 --- a/src/test/java/org/json/junit/XMLTest.java +++ b/src/test/java/org/json/junit/XMLTest.java @@ -1239,8 +1239,8 @@ public class XMLTest { for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) { expected.append(buffer, 0, numRead); } - assertEquals(expected.toString().replaceAll("\\n|\\r\\n", System.getProperty("line.separator")), - actualString.replaceAll("\\n|\\r\\n", System.getProperty("line.separator"))); + assertEquals(expected.toString().replaceAll("\\n|\\r\\n", System.lineSeparator()), + actualString.replaceAll("\\n|\\r\\n", System.lineSeparator())); } finally { if (xmlStream != null) { xmlStream.close();