DocumentLoader { public Document loadFromUrl(String strUrl) throws fr.norad.visuwall.providers.common.DocumentNotLoadedException { Preconditions.checkNotNull(strUrl, "strUrl is mandatory"); InputStream stream = null; try { URL url = new URL(strUrl); stream = url.openStream(); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder(); return documentBuilder.parse(stream); } catch (MalformedURLException e) { throw new fr.norad.visuwall.providers.common.DocumentNotLoadedException("Can't load document from url: " + strUrl, e); } catch (IOException e) { throw new fr.norad.visuwall.providers.common.DocumentNotLoadedException("Can't load document from url: " + strUrl, e); } catch (SAXException e) { throw new fr.norad.visuwall.providers.common.DocumentNotLoadedException("Can't load document from url: " + strUrl, e); } catch (ParserConfigurationException e) { throw new fr.norad.visuwall.providers.common.DocumentNotLoadedException("Can't load document from url: " + strUrl, e); } finally { closeQuietly(stream); } }  Document loadFromUrl(String strUrl); Document loadFromContent(String pomContent);  }
@Test public void should_load_valid_xml_file() throws Exception { String fileUrl = ClasspathFiles.getAbsolutePathFile("pom-sample.xml"); Document document = documentLoader.loadFromUrl(fileUrl); assertNotNull(document); }
@Test(expected = DocumentNotLoadedException.class) public void should_fail_with_other_type_than_xml() throws Exception { String fileUrl = ClasspathFiles.getAbsolutePathFile("simple-text-file.txt"); documentLoader.loadFromUrl(fileUrl); }
@Test(expected = NullPointerException.class) public void should_not_accept_null_parameter() throws Exception { documentLoader.loadFromUrl(null); }