ModuleRepositoriesContentHandler { public ModuleRepositories toModel(final String text) { try { if (text == null || text.isEmpty()) { return new ModuleRepositories(); } return (ModuleRepositories) createXStream().fromXML(text); } catch (Exception e) { return new ModuleRepositories(); } } ModuleRepositoriesContentHandler(); String toString(final ModuleRepositories repositories); ModuleRepositories toModel(final String text);  }
@Test public void testNullSourceXml() throws Exception { final ModuleRepositories repositories = handler.toModel(null); assertNotNull(repositories); assertEquals(0, repositories.getRepositories().size()); }
@Test public void testEmptySourceXml() throws Exception { final ModuleRepositories repositories = handler.toModel(""); assertNotNull(repositories); assertEquals(0, repositories.getRepositories().size()); }
@Test public void testRepositoriesUnmarshalling() throws Exception { final String xml = "<project-repositories>\n" + " <repositories>\n" + " <repository>\n" + " <include>true</include>\n" + " <metadata>\n" + " <id>id</id>\n" + " <url>url</url>\n" + " <source>LOCAL</source>\n" + " </metadata>\n" + " </repository>\n" + " </repositories>\n" + "</project-repositories>"; final ModuleRepositories repositories = handler.toModel(xml); assertNotNull(repositories); assertNotNull(repositories.getRepositories()); assertEquals(1, repositories.getRepositories().size()); final ModuleRepositories.ModuleRepository repository = repositories.getRepositories().iterator().next(); assertEquals("id", repository.getMetadata().getId()); assertEquals("url", repository.getMetadata().getUrl()); assertEquals(MavenRepositorySource.LOCAL, repository.getMetadata().getSource()); assertEquals(true, repository.isIncluded()); }
@Test public void testRepositoriesUnmarshalling_InvalidXml() throws Exception { final String xml = "<project-repositories>\n" + " <repositories>\n" + " <repository>\n" + " <include>true</include>\n" + " <cheese>\n" + " <name>cheddar</name>\n" + " </cheese>\n" + " </repository>\n" + " </repositories>\n" + "</project-repositories>"; final ModuleRepositories repositories = handler.toModel(xml); assertNotNull(repositories); assertNotNull(repositories.getRepositories()); assertEquals(0, repositories.getRepositories().size()); }