org.hamcrest.xml
Class HasXPath
java.lang.Object
org.hamcrest.BaseMatcher<T>
org.hamcrest.TypeSafeDiagnosingMatcher<Node>
org.hamcrest.xml.HasXPath
- All Implemented Interfaces:
- Matcher<Node>, SelfDescribing
public class HasXPath
- extends TypeSafeDiagnosingMatcher<Node>
Applies a Matcher to a given XML Node in an existing XML Node tree, specified by an XPath expression.
- Author:
- Joe Walnes, Steve Freeman
NO_NAMESPACE_CONTEXT
public static final NamespaceContext NO_NAMESPACE_CONTEXT
HasXPath
public HasXPath(String xPathExpression,
Matcher<String> valueMatcher)
- Parameters:
xPathExpression - XPath expression.valueMatcher - Matcher to use at given XPath.
May be null to specify that the XPath must exist but the value is irrelevant.
HasXPath
public HasXPath(String xPathExpression,
NamespaceContext namespaceContext,
Matcher<String> valueMatcher)
- Parameters:
xPathExpression - XPath expression.namespaceContext - Resolves XML namespace prefixes in the XPath expressionvalueMatcher - Matcher to use at given XPath.
May be null to specify that the XPath must exist but the value is irrelevant.
matchesSafely
public boolean matchesSafely(Node item,
Description mismatch)
- Specified by:
matchesSafely in class TypeSafeDiagnosingMatcher<Node>
describeTo
public void describeTo(Description description)
hasXPath
public static Matcher<Node> hasXPath(String xPath,
Matcher<String> valueMatcher)
- Creates a matcher of
Nodes that matches when the examined node has a value at the
specified xPath that satisfies the specified valueMatcher.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))
- Parameters:
xPath - the target xpathvalueMatcher - matcher for the value at the specified xpath
hasXPath
public static Matcher<Node> hasXPath(String xPath,
NamespaceContext namespaceContext,
Matcher<String> valueMatcher)
- Creates a matcher of
Nodes that matches when the examined node has a value at the
specified xPath, within the specified namespaceContext, that satisfies
the specified valueMatcher.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))
- Parameters:
xPath - the target xpathnamespaceContext - the namespace for matching nodesvalueMatcher - matcher for the value at the specified xpath
hasXPath
public static Matcher<Node> hasXPath(String xPath)
- Creates a matcher of
Nodes that matches when the examined node contains a node
at the specified xPath, with any content.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese"))
- Parameters:
xPath - the target xpath
hasXPath
public static Matcher<Node> hasXPath(String xPath,
NamespaceContext namespaceContext)
- Creates a matcher of
Nodes that matches when the examined node contains a node
at the specified xPath within the specified namespace context, with any content.
For example:
assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))
- Parameters:
xPath - the target xpathnamespaceContext - the namespace for matching nodes
Copyright © 2014. All rights reserved.