Skip to content

Commit 0e4a94d

Browse files
committed
fix failing test XML test on Windows machines
1 parent 79af389 commit 0e4a94d

File tree

1 file changed

+11
-25
lines changed

1 file changed

+11
-25
lines changed

src/test/java/org/json/junit/XMLTest.java

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,32 +1223,18 @@ public void testIndentSimpleJsonArray(){
12231223

12241224
@Test
12251225
public void testIndentComplicatedJsonObjectWithArrayAndWithConfig(){
1226-
try {
1227-
InputStream jsonStream = null;
1228-
try {
1229-
jsonStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.json");
1230-
final JSONObject object = new JSONObject(new JSONTokener(jsonStream));
1231-
String actualString = XML.toString(object, null, XMLParserConfiguration.KEEP_STRINGS,2);
1232-
InputStream xmlStream = null;
1233-
try {
1234-
xmlStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.xml");
1235-
int bufferSize = 1024;
1236-
char[] buffer = new char[bufferSize];
1237-
StringBuilder expected = new StringBuilder();
1238-
Reader in = new InputStreamReader(xmlStream, "UTF-8");
1239-
for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) {
1240-
expected.append(buffer, 0, numRead);
1241-
}
1242-
assertEquals(expected.toString(), actualString.replaceAll("\\n|\\r\\n", System.getProperty("line.separator")));
1243-
} finally {
1244-
if (xmlStream != null) {
1245-
xmlStream.close();
1246-
}
1247-
}
1248-
} finally {
1249-
if (jsonStream != null) {
1250-
jsonStream.close();
1226+
try (InputStream jsonStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.json")) {
1227+
final JSONObject object = new JSONObject(new JSONTokener(jsonStream));
1228+
String actualString = XML.toString(object, null, XMLParserConfiguration.KEEP_STRINGS, 2);
1229+
try (InputStream xmlStream = XMLTest.class.getClassLoader().getResourceAsStream("Issue593.xml")) {
1230+
int bufferSize = 1024;
1231+
char[] buffer = new char[bufferSize];
1232+
StringBuilder expected = new StringBuilder();
1233+
Reader in = new InputStreamReader(xmlStream, "UTF-8");
1234+
for (int numRead; (numRead = in.read(buffer, 0, buffer.length)) > 0; ) {
1235+
expected.append(buffer, 0, numRead);
12511236
}
1237+
assertEquals(expected.toString(), actualString);
12521238
}
12531239
} catch (IOException e) {
12541240
fail("file writer error: " +e.getMessage());

0 commit comments

Comments
 (0)