Skip to content

Commit

Permalink
fix failing test XML test on Windows machines
Browse files Browse the repository at this point in the history
  • Loading branch information
Madjosz committed Oct 7, 2023
1 parent 79af389 commit 0e4a94d
Showing 1 changed file with 11 additions and 25 deletions.
36 changes: 11 additions & 25 deletions src/test/java/org/json/junit/XMLTest.java
Expand Up @@ -1223,32 +1223,18 @@ public void testIndentSimpleJsonArray(){

@Test
public void testIndentComplicatedJsonObjectWithArrayAndWithConfig(){
try {
InputStream jsonStream = null;
try {
jsonStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.json");
final JSONObject object = new JSONObject(new JSONTokener(jsonStream));
String actualString = XML.toString(object, null, XMLParserConfiguration.KEEP_STRINGS,2);
InputStream xmlStream = null;
try {
xmlStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.xml");
int bufferSize = 1024;
char[] buffer = new char[bufferSize];
StringBuilder expected = new StringBuilder();
Reader in = new InputStreamReader(xmlStream, "UTF-8");
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")));
} finally {
if (xmlStream != null) {
xmlStream.close();
}
}
} finally {
if (jsonStream != null) {
jsonStream.close();
try (InputStream jsonStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.json")) {
final JSONObject object = new JSONObject(new JSONTokener(jsonStream));
String actualString = XML.toString(object, null, XMLParserConfiguration.KEEP_STRINGS, 2);
try (InputStream xmlStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.xml")) {
int bufferSize = 1024;
char[] buffer = new char[bufferSize];
StringBuilder expected = new StringBuilder();
Reader in = new InputStreamReader(xmlStream, "UTF-8");
for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) {
expected.append(buffer, 0, numRead);
}
assertEquals(expected.toString(), actualString);
}
} catch (IOException e) {
fail("file writer error: " +e.getMessage());
Expand Down

0 comments on commit 0e4a94d

Please sign in to comment.