### Question:
DocumentFactory { public static Document createDocument() { return getDocumentFactory().newDocument(); } private  DocumentFactory(); static Document createDocument(); static Document createDocument(InputStream input); static Transformer createTransformer();  }### Answer:
@Test void testCreateDocument() throws IOException { assertNotNull(DocumentFactory.createDocument()); try (InputStream input = DocumentFactoryTest.class.getResourceAsStream("type.xml")) { assertNotNull(DocumentFactory.createDocument(input)); } }
@Test void testCreateDocumentMalformed() throws IOException { try (InputStream input = DocumentFactoryTest.class.getResourceAsStream("malformed.xml")) { final String message = "org.xml.sax.SAXParseException; lineNumber: 4; columnNumber: 7; "; assertThrowsIo(() -> DocumentFactory.createDocument(input), message); } }
@Test void testCreateDocumentNullStream() throws IOException { assertThrows(() -> DocumentFactory.createDocument(null), Check.ERROR_NULL); }
@Test void testMissingFeature() throws Exception { final Object old = UtilReflection.getField(DocumentFactory.class, "documentBuilder"); final Field field = DocumentFactory.class.getDeclaredField("documentBuilder"); UtilReflection.setAccessible(field, true); field.set(DocumentFactory.class, null); final String oldFactory = System.getProperty(DocumentBuilderFactory.class.getName()); System.setProperty(DocumentBuilderFactory.class.getName(), Factory.class.getName()); try { Verbose.info("*********************************** EXPECTED VERBOSE ***********************************"); assertCause(() -> DocumentFactory.createDocument(), ParserConfigurationException.class); Verbose.info("****************************************************************************************"); } finally { if (oldFactory != null) { System.setProperty(DocumentBuilderFactory.class.getName(), oldFactory); } else { System.setProperty(DocumentBuilderFactory.class.getName(), ""); } field.set(DocumentFactory.class, old); UtilReflection.setAccessible(field, false); } }