@Test public void testExecute() throws Exception { final ResourceFetcher resourceFetcher = context.mock(ResourceFetcher.class); final String fileName = "sdlkfjsdljfdsj.xml"; DocumentCreator sut = new DocumentCreator(resourceFetcher); context.checking(new Expectations() { { one(resourceFetcher).getInputStream(fileName); will(returnValue(new ByteArrayInputStream("<xml><foo rel=\"bar\"/></xml>".getBytes()))); } }); Document doc = sut.execute(fileName); assertEquals(1, doc.getChildNodes().getLength()); assertEquals(1, doc.getElementsByTagName("xml").getLength()); assertEquals(1, doc.getElementsByTagName("foo").getLength()); assertEquals("bar", doc.getElementsByTagName("foo").item(0).getAttributes().item(0).getTextContent()); }
public Document execute(final String inFileName) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); log.info("Fetching and parsing input stream from " + inFileName); return db.parse(xmlFetcher.getInputStream(inFileName)); }
DocumentCreator { public Document execute(final String inFileName) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); log.info("Fetching and parsing input stream from " + inFileName); return db.parse(xmlFetcher.getInputStream(inFileName)); } }
DocumentCreator { public Document execute(final String inFileName) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); log.info("Fetching and parsing input stream from " + inFileName); return db.parse(xmlFetcher.getInputStream(inFileName)); } DocumentCreator(final ResourceFetcher inXMLFetcher); }
DocumentCreator { public Document execute(final String inFileName) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); log.info("Fetching and parsing input stream from " + inFileName); return db.parse(xmlFetcher.getInputStream(inFileName)); } DocumentCreator(final ResourceFetcher inXMLFetcher); Document execute(final String inFileName); }
DocumentCreator { public Document execute(final String inFileName) throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); log.info("Fetching and parsing input stream from " + inFileName); return db.parse(xmlFetcher.getInputStream(inFileName)); } DocumentCreator(final ResourceFetcher inXMLFetcher); Document execute(final String inFileName);  }