HasXPath extends TypeSafeDiagnosingMatcher<Node> { public HasXPath(String xPathExpression, Matcher<String> valueMatcher) { this(xPathExpression, NO_NAMESPACE_CONTEXT, valueMatcher); } HasXPath(String xPathExpression, Matcher<String> valueMatcher);  HasXPath(String xPathExpression, NamespaceContext namespaceContext, Matcher<String> valueMatcher); private  HasXPath(String xPathExpression, NamespaceContext namespaceContext, Matcher<String> valueMatcher, QName mode); @Override boolean matchesSafely(Node item, Description mismatch); @Override void describeTo(Description description); static Matcher<Node> hasXPath(String xPath, Matcher<String> valueMatcher); static Matcher<Node> hasXPath(String xPath, NamespaceContext namespaceContext, Matcher<String> valueMatcher); static Matcher<Node> hasXPath(String xPath); static Matcher<Node> hasXPath(String xPath, NamespaceContext namespaceContext); static final NamespaceContext NO_NAMESPACE_CONTEXT; }
@Test public void copesWithNullsAndUnknownTypes() { Matcher<Node> matcher = hasXPath(" assertNullSafe(matcher); assertUnknownTypeSafe(matcher); }
@Test public void describesIncorrectNodeValueMismatch() { assertMismatchDescription("was \"Edam\"", hasXPath(" }
@Test public void appliesMatcherToXPathInDocument() { assertMatches(hasXPath("/root/something[2]/cheese", equalTo("Cheddar")), xml); assertMatches(hasXPath(" assertMatches(hasXPath(" assertMatches(hasXPath("/root/@type", equalTo("food")), xml); assertMatches(hasXPath(" assertMatches(hasXPath(" }
@Test public void matchesEmptyElement() { assertMatches(hasXPath(" }
@Test public void matchesEmptyElementInNamespace() { assertMatches(hasXPath(" }
@Test public void failsIfNodeIsMissing() { assertDoesNotMatch(hasXPath("/root/something[3]/cheese", ns, equalTo("Cheddar")), xml); assertDoesNotMatch(hasXPath(" }
@Test public void failsIfNodeIsMissingInNamespace() { assertDoesNotMatch(hasXPath(" assertDoesNotMatch(hasXPath(" }
@Test public void matchesWithNamespace() { assertMatches(hasXPath(" assertMatches(hasXPath(" assertMatches(hasXPath(" }
@Test public void throwsIllegalArgumentExceptionIfGivenIllegalExpression() { try { hasXPath("\\g:dfgd::DSgf/root/something[2]/cheese", equalTo("blah")); fail("Expected exception"); } catch (IllegalArgumentException expectedException) { } }
@Test public void describesItself() { assertDescription("an XML document with XPath /some/path \"Cheddar\"", hasXPath("/some/path", equalTo("Cheddar"))); assertDescription("an XML document with XPath /some/path", hasXPath("/some/path")); }
@Test public void describesMissingNodeMismatch() { assertMismatchDescription("xpath returned no results.", hasXPath(" }