Merge pull request #778 from Madjosz/fix_xml_test

Fix XMLTest.testIndentComplicatedJsonObjectWithArrayAndWithConfig() for Windows - in the test
This commit is contained in:
Sean Leary 2023-10-08 17:06:55 -05:00 committed by GitHub
commit 776b5ccb85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1223,15 +1223,10 @@ public class XMLTest {
@Test
public void testIndentComplicatedJsonObjectWithArrayAndWithConfig(){
try {
InputStream jsonStream = null;
try {
jsonStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.json");
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);
InputStream xmlStream = null;
try {
xmlStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.xml");
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();
@ -1239,17 +1234,7 @@ 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.lineSeparator()),
actualString.replaceAll("\\n|\\r\\n", System.lineSeparator()));
} finally {
if (xmlStream != null) {
xmlStream.close();
}
}
} finally {
if (jsonStream != null) {
jsonStream.close();
}
assertEquals(expected.toString(), actualString);
}
} catch (IOException e) {
fail("file writer error: " +e.getMessage());