AbstractHTMLFilter implements HTMLFilter, HTMLConstants { protected List<Element> filterDescendants(Element parent, String[] tagNames) { List<Element> result = new ArrayList<>(); for (String tagName : tagNames) { NodeList nodes = parent.getElementsByTagName(tagName); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); result.add(element); } } return result; }    }
@Test void filterDescendants() { Document document = this.cleaner.clean(new StringReader("<html><head><body><p>test1</p><p>test2</p></body></html>")); List<Element> paragraphs = htmlFilter.filterDescendants(document.getDocumentElement(), new String[]{ "p" }); assertEquals(2, paragraphs.size()); assertEquals("test1", paragraphs.get(0).getTextContent()); assertEquals("test2", paragraphs.get(1).getTextContent()); }