/** * Test that {@link PawpedsDocumentParser#parseSearch(Document)} throws an * {@link IllegalArgumentException} if there is an jsoup parsing error. */ @Test(expected = IllegalArgumentException.class) public void testJsoupSelectorUnexpectedError() throws Exception { // Given Document document = mock(Document.class); Elements noErrorElement = mock(Elements.class); when(noErrorElement.text()).thenReturn(""); when(document.select("th.error")).thenReturn(noErrorElement); when(document.select("table.searchresult tr.searchresult:has(td.searchresult)")).thenThrow(SelectorParseException.class); // When pawpedsDocumentParser.parseSearch(document); // Then // the exception is expected }
private LinkedList<String> doFilter(Document jsoup, Set<String> jsoupSelectors) throws IOException { LinkedList<String> result = new LinkedList<String>(); for (String jsoupSel : jsoupSelectors) { try { for (Element e : jsoup.select(jsoupSel)) { result.add(e.outerHtml()); } } catch (SelectorParseException xpe) { throw new IllegalArgumentException("error while processing jsoup selector: '" + jsoupSel + "'", xpe); } } return result; }
/** * http://www.ibm.com/developerworks/library/x-javaxpathapi.html * * @param expr * @return */ @Override public DOMHandler cssLikeSelectNodeSet(String expr) { if (StringUtils.isNotBlank(expr)) { try { selectedElements = jsoupDocument.select(expr); } catch (SelectorParseException spe) { } catch (IllegalArgumentException iae) { } } return this; }