EHFatalTest.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:openjdk-jdk10 作者:
/**
 * Error Handler to capture all error events to output file. Verifies the
 * output file is same as golden file.
 *
 * @throws Exception If any errors occur.
 */
@Test
public void testEHFatal() throws Exception {
    String outputFile = USER_DIR + "EHFatal.out";
    String goldFile = GOLDEN_DIR + "EHFatalGF.out";
    String xmlFile = XML_DIR + "invalid.xml";

    try(MyErrorHandler eHandler = new MyErrorHandler(outputFile);
            FileInputStream instream = new FileInputStream(xmlFile)) {
        SAXParser saxParser = SAXParserFactory.newInstance().newSAXParser();
        XMLReader xmlReader = saxParser.getXMLReader();
        xmlReader.setErrorHandler(eHandler);
        InputSource is = new InputSource(instream);
        xmlReader.parse(is);
        fail("Parse should throw SAXException");
    } catch (SAXException expected) {
        // This is expected.
    }
    // Need close the output file before we compare it with golden file.
    assertTrue(compareWithGold(goldFile, outputFile));
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号