Skip to content

Commit

Permalink
Merge pull request #778 from Madjosz/fix_xml_test
Browse files Browse the repository at this point in the history
Fix XMLTest.testIndentComplicatedJsonObjectWithArrayAndWithConfig() for Windows - in the test
  • Loading branch information
stleary committed Oct 8, 2023
2 parents bc09f90 + fb99c06 commit 776b5cc
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions src/test/java/org/json/junit/XMLTest.java
Expand Up @@ -1223,33 +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().replaceAll("\\n|\\r\\n", System.lineSeparator()),
actualString.replaceAll("\\n|\\r\\n", System.lineSeparator()));
} 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 776b5cc

Please sign in to comment.