SafeXml { public static DocumentBuilderFactory newStrictDocumentBuilderFactory() throws ParserConfigurationException { DocumentBuilderFactory factory = newdocumentBuilderFactory(); factory.setFeature(APACHE_DISALLOW_DOCTYPE_DECL, true); return factory; } private  SafeXml(); static XMLInputFactory newXmlInputFactory(); static DocumentBuilderFactory newdocumentBuilderFactory(); static DocumentBuilderFactory newStrictDocumentBuilderFactory(); static TransformerFactory newTransformerFactory(); static SAXTransformerFactory newSaxTransformerFactory(); static SAXParserFactory newSaxParserFactory(); static SAXParserFactory newStrictSaxParserFactory();  }
@Test public void testStrictDocumentBuilderFactory() throws IOException, SAXException, ParserConfigurationException { thrown.expect(SAXParseException.class); thrown.expectMessage(containsString("DOCTYPE is disallowed")); DocumentBuilder builder = SafeXml.newStrictDocumentBuilderFactory().newDocumentBuilder(); builder.parse(xmlDocument); }