OutputHandler { public void writeOutput(Document dom, File file) throws IOException { FileOutputStream out = null; try { out = new FileOutputStream(file); writeOutput(dom, out); } finally { IOUtil.closeQuietly(out); } } OutputHandler(CommandLine args); void writeOutput(Document dom, File file); void writeOutput(Document dom, OutputStream out0);  }
@Test public void testNoPrettyPrint() throws Exception { CommandLine args = new CommandLine("--noPrettyPrint"); String src = "<root> <child>value</child> \n </root>"; Document dom = ParseUtil.parse(src); ByteArrayOutputStream out = new ByteArrayOutputStream(); new OutputHandler(args).writeOutput(dom, out); assertEquals("no transform", src, getOutput(out)); }
@Test public void testPrettyPrint() throws Exception { CommandLine args = new CommandLine("--prettyPrint=3"); String src = "<root> <child>value</child> \n </root>"; Document dom = ParseUtil.parse(src); ByteArrayOutputStream out = new ByteArrayOutputStream(); new OutputHandler(args).writeOutput(dom, out); assertEquals("<root>\n <child>value</child>\n</root>", getOutput(out)); }
@Test public void testWriteToFile() throws Exception { CommandLine args = new CommandLine("--noPrettyPrint"); String src = "<root><child>value</child></root>"; Document dom = ParseUtil.parse(src); File dest = IOUtil.createTempFile("testWriteToFile", 0); new OutputHandler(args).writeOutput(dom, dest); assertEquals(src.length(), dest.length()); }