HasXPath extends TypeSafeMatcher<Source> { protected HasXPath(String xPathExpression) { this(xPathExpression, null, null); } protected  HasXPath(String xPathExpression); protected  HasXPath(String xPathExpression, Matcher<? super String> valueMatcher,
			NamespaceContext namespaceContext);  HasXPath(String xPathExpression, Matcher<?> valueMatcher,
			NamespaceContext namespaceContext, XpathReturnType<?> xPathReturnType); void describeTo(Description description); @Override boolean matchesSafely(Source source); @Factory static Matcher<Source> hasXPath(String xPath); @Factory static Matcher<Source> hasXPath(String xPath,
			NamespaceContext namespaceContext); @Factory static Matcher<Source> hasXPath(String xPath,
			Matcher<? super String> valueMatcher); @Factory static Matcher<Source> hasXPath(String xPath,
			NamespaceContext namespaceContext, Matcher<? super String> valueMatcher); @Factory static Matcher<Source> hasXPath(String xPath,
			XpathReturnType<? super T> xpathReturnType,
			Matcher<? super T> valueMatcher); @Factory static Matcher<Source> hasXPath(String xPath,
			NamespaceContext namespaceContext,
			XpathReturnType<? super T> xpathReturnType,
			Matcher<? super T> valueMatcher); @Factory static Matcher<Source> hasXPath(String xPath,
			Matcher<? super String> valueMatcher, NamespaceContext namespaceContext);  }
@Test public void theResultOfTheXpathCanMatchedUsingEquivalentToWhenTheResultIsAnXmlFragment() { assertThat( xml, hasXPath("/mountains/mountain[@id='a']/name", returningAnXmlNode(), equivalentTo(xml("<name>Everest</name>")))); }
@Test public void matchingNodesCanBeTestedForEquivalence() { assertThat( xml, hasXPath( "/mountains/mountain[@id='a']/name", returningAnXmlNode(), equivalentTo(xml("<name><!-- some comment -->Everest</name>")))); }
@Test public void theResultOfTheXpathCanMatchedUsingEquivalentToWhenTheResultIsAString() { assertThat( xml, hasXPath("/mountains/m:oceanRidge/@m:depth", usingNamespaces, equalTo("-5000"))); assertThat(xml, hasXPath("/mountains/mountain[@id='a']/@altname", equalTo(""))); assertThat( xml, hasXPath("/mountains/mountain[@id='a']/name", equalToIgnoringCase("EVEREST"))); assertThat( xml, hasXPath("/mountains/mountain[@id='a']/name/text()", equalToIgnoringCase("EvErEsT"))); }
@Test public void theResultOfTheXpathCanMatchedUsingEquivalentToWhenTheResultIsANumber() { assertThat( xml, hasXPath("/mountains/volcanoe/@eruptions", returningANumber(), equalTo(2.0))); assertThat( xml, hasXPath("/mountains/volcanoe/@eruptions", returningANumber(), closeTo(4, 2))); assertThat( xml, hasXPath("/mountains/volcanoe/@eruptions", returningANumber(), lessThan(5d))); assertThat( xml, hasXPath("/mountains/volcanoe/@eruptions", returningANumber(), lessThanOrEqualTo(5.0))); assertThat( xml, hasXPath("count(/mountains/mountain)", returningANumber(), equalTo(2d))); }
@Test public void attributeOrNodeValuesCannotBeConvertedToBooleans() { assertThat(xml, not(hasXPath("/mountains/volcanoe/@good", returningABoolean(), equalTo(false)))); }
@Test public void theResultOfTheXpathCanMatchedUsingEquivalentToWhenTheResultIsABoolean() { assertThat(xml, hasXPath("/mountains/volcanoe/@good", returningABoolean(), equalTo(true))); assertThat(xml, hasXPath("not(/mountains/climber)", returningABoolean(), equalTo(true))); assertThat(xml, hasXPath("not(/mountains/volcanoe/@good)", returningABoolean(), equalTo(false))); }
@Test public void theResultOfTheXpathCanMatchedUsingStringContains() { assertThat( xml, hasXPath("/mountains/mountain[@id='a']/name", containsString("Everest"))); }
@Test public void matchesNodesInTheXmlWhenNoNamespacesAreBound() { assertThat(xml, hasXPath("/mountains")); assertThat(xml, hasXPath("/mountains/mountain")); assertThat(xml, hasXPath("/mountains/mountain[2]/name")); assertThat(xml, hasXPath("/mountains/oceanRidge")); assertThat(xml, hasXPath("/mountains/mountain[@id='a']/@altname")); }
@Test public void ifANodeIsPrefixedByANamespaceAndNamespacesAreNotBoundXpathWillNotFindIt() { assertThat(xml, not(hasXPath("/mountains/range"))); }
@Test public void functionsCanBeUsedToReturnDataThatCanBeMatchedAgainst() { assertThat(xml, hasXPath("count(/mountains/mountain)", equalTo("2"))); assertThat(xml, hasXPath("count(/mountains/mountain)", returningANumber(), greaterThanOrEqualTo(2d))); assertThat(xml, hasXPath("count(/mountains/mountain)", returningANumber(), not(lessThanOrEqualTo(1d)))); }
@Test public void matchesNodesInTheXmlWhenNamespacesAreBound() { assertThat(xml, hasXPath("/mountains", usingNamespaces)); assertThat(xml, hasXPath("/mountains/mountain", usingNamespaces)); assertThat(xml, hasXPath("/mountains/mountain[2]/name", usingNamespaces)); assertThat(xml, hasXPath("/mountains/oceanRidge", usingNamespaces)); assertThat(xml, not(hasXPath("/mountains/range"))); assertThat(xml, hasXPath("/mountains/m:range", usingNamespaces)); }
@Test public void matchesAttributesInTheXmlWhenNoNamespacesAreBound() { assertThat(xml, hasXPath("/mountains/@type")); }
@Test public void matchesAttributesInTheXmlWhenNamespacesAreBound() { assertThat(xml, hasXPath("/mountains/m:oceanRidge/@m:depth", usingNamespaces)); }