### Question:
XmlUtil { public static List<Element> parse( final String xml, final String requestedNodes ) { if( StringUtils.isNotEmpty( xml ) && StringUtils.isNotEmpty( requestedNodes ) ) { final Set<Element> readed = new HashSet<>(); final SAXBuilder builder = new SAXBuilder(); try { final Enumeration< URL > resources = XmlUtil.class.getClassLoader().getResources( xml ); while( resources.hasMoreElements() ) { final URL resource = resources.nextElement(); LOG.debug( "reading " + resource.toString() ); final Document doc = builder.build( resource ); final XPathFactory xpfac = XPathFactory.instance(); final XPathExpression<Element> xp = xpfac.compile( requestedNodes, Filters.element() ); readed.addAll( xp.evaluate( doc ) ); } return new ArrayList<>( readed ); } catch( final IOException ioe ) { LOG.error( "Couldn't load all " + xml + " resources", ioe ); } catch( final JDOMException jdome ) { LOG.error( "error parsing " + xml + " resources", jdome ); } } return Collections.emptyList(); } private  XmlUtil(); static List<Element> parse( final String xml, final String requestedNodes ); static List< Element > parse( final InputStream xmlStream, final String requestedNodes ); static String extractTextFromDocument( final Document doc );  }### Answer:
@Test public void testParseFromClasspath() { List< Element > elements = XmlUtil.parse( "ini/jspwiki_module.xml", "/modules/plugin" ); Assertions.assertEquals( 2, elements.size() ); elements = XmlUtil.parse( "ini/jspwiki_module.xml", "/modules/filter" ); Assertions.assertEquals( 1, elements.size() ); elements = XmlUtil.parse( "ini/jspwiki_module.xml", "/modules/editor" ); Assertions.assertEquals( 2, elements.size() ); elements = XmlUtil.parse( "ini/jspwiki_module.xml", "/modules/heck" ); Assertions.assertEquals( 0, elements.size() ); elements = XmlUtil.parse( "doesnt/exist.this", "/modules/editor" ); Assertions.assertEquals( 0, elements.size() ); elements = XmlUtil.parse( ( String )null, "/modules/editor" ); Assertions.assertEquals( 0, elements.size() ); elements = XmlUtil.parse( "ini/jspwiki_module.xml", null ); Assertions.assertEquals( 0, elements.size() ); elements = XmlUtil.parse( ClassUtil.MAPPINGS, "/classmappings/mapping" ); Assertions.assertEquals( 1, elements.size() ); }
@Test public void testParseFromStream() throws IOException { try( final InputStream is = new FileInputStream( new File ("./src/test/resources/ini/jspwiki_module.xml" ) ) ) { List< Element > elements = XmlUtil.parse( is, "/modules/plugin" ); Assertions.assertEquals( 2, elements.size() ); elements = XmlUtil.parse( is, "/modules/filter" ); Assertions.assertEquals( 0, elements.size() ); elements = XmlUtil.parse( is, "/modules/editor" ); Assertions.assertEquals( 0, elements.size() ); elements = XmlUtil.parse( is, "/modules/heck" ); Assertions.assertEquals( 0, elements.size() ); elements = XmlUtil.parse( ( InputStream )null, "/modules/editor" ); Assertions.assertEquals( 0, elements.size() ); elements = XmlUtil.parse( is, null ); Assertions.assertEquals( 0, elements.size() ); } }