diff --git a/jdk/test/javax/xml/jaxp/transform/8268457/SurrogateTest.java b/jdk/test/javax/xml/jaxp/transform/8268457/SurrogateTest.java index 79fa503554..626c81d264 100644 --- a/jdk/test/javax/xml/jaxp/transform/8268457/SurrogateTest.java +++ b/jdk/test/javax/xml/jaxp/transform/8268457/SurrogateTest.java @@ -24,14 +24,14 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.stream.Collectors; +import java.util.ArrayList; +import java.util.List; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; @@ -59,10 +59,11 @@ public class SurrogateTest { public void toHTMLTest() throws Exception { String out = "SurrogateTest1out.html"; String expected = TEST_SRC + File.separator + "SurrogateTest1.html"; + String xml = TEST_SRC + File.separator + "SurrogateTest1.xml"; String xsl = TEST_SRC + File.separator + "SurrogateTest1.xsl"; try (FileInputStream tFis = new FileInputStream(xsl); - InputStream fis = this.getClass().getResourceAsStream("SurrogateTest1.xml"); + InputStream fis = new FileInputStream(xml); FileOutputStream fos = new FileOutputStream(out)) { Source tSrc = new StreamSource(tFis); @@ -74,7 +75,9 @@ public void toHTMLTest() throws Exception { Result res = new StreamResult(fos); t.transform(src, res); } - compareWithGold(expected, out); + if (!compareWithGold(expected, out)) { + throw new RuntimeException("toHTMLTest failed"); + } } public void handlerTest() throws Exception { @@ -84,15 +87,17 @@ public void handlerTest() throws Exception { SAXParser sp = spf.newSAXParser(); TestHandler th = new TestHandler(); sp.parse(xmlFile, th); - compareStringWithGold(TEST_SRC + File.separator + "SurrogateTest2.txt", th.sb.toString()); + if (!compareLinesWithGold(TEST_SRC + File.separator + "SurrogateTest2.txt", th.lines)) { + throw new RuntimeException("handlerTest failed"); + } } private static class TestHandler extends DefaultHandler { - private StringBuilder sb = new StringBuilder(); + private List lines = new ArrayList<>(); @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { - sb.append( localName + "@attr:" + attributes.getValue("attr") + '\n'); + lines.add( localName + "@attr:" + attributes.getValue("attr")); } } @@ -122,11 +127,9 @@ public static boolean compareWithGold(String goldfile, String outputfile, return isSame; } - // Compare contents of golden file with a test output string. - public static boolean compareStringWithGold(String goldfile, String string) + // Compare contents of golden file with test output list line by line. + public static boolean compareLinesWithGold(String goldfile, List lines) throws IOException { - return Files.readAllLines(Paths.get(goldfile)).stream().collect( - Collectors.joining(System.getProperty("line.separator"))) - .equals(string); + return Files.readAllLines(Paths.get(goldfile)).equals(lines); } }