Package org.hamcrest.xml
Class HasXPath
- All Implemented Interfaces:
Matcher<Node>,SelfDescribing
Applies a Matcher to a given XML Node in an existing XML Node tree, specified by an XPath expression.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final XPathExpressionprivate final QNamestatic final NamespaceContextprivate static final Condition.Step<Object, String> private static final IsAnything<String> private final String -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static XPathExpressioncompiledXPath(String xPathExpression, NamespaceContext namespaceContext) voiddescribeTo(Description description) Generates a description of the object.evaluated(Node item, Description mismatch) Creates a matcher ofNodes that matches when the examined node contains a node at the specifiedxPath, with any content.hasXPath(String xPath, NamespaceContext namespaceContext) Creates a matcher ofNodes that matches when the examined node contains a node at the specifiedxPathwithin the specified namespace context, with any content.hasXPath(String xPath, NamespaceContext namespaceContext, Matcher<String> valueMatcher) Creates a matcher ofNodes that matches when the examined node has a value at the specifiedxPath, within the specifiednamespaceContext, that satisfies the specifiedvalueMatcher.Creates a matcher ofNodes that matches when the examined node has a value at the specifiedxPaththat satisfies the specifiedvalueMatcher.booleanmatchesSafely(Node item, Description mismatch) Subclasses should implement this.private static Condition.Step<Object, String> Methods inherited from class org.hamcrest.TypeSafeDiagnosingMatcher
describeMismatch, matchesMethods inherited from class org.hamcrest.BaseMatcher
_dont_implement_Matcher___instead_extend_BaseMatcher_, isNotNull, toString
-
Field Details
-
NO_NAMESPACE_CONTEXT
-
WITH_ANY_CONTENT
-
NODE_EXISTS
-
valueMatcher
-
compiledXPath
-
xpathString
-
evaluationMode
-
-
Constructor Details
-
HasXPath
- 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.
-
HasXPath
private HasXPath(String xPathExpression, NamespaceContext namespaceContext, Matcher<String> valueMatcher, QName mode)
-
-
Method Details
-
matchesSafely
Description copied from class:TypeSafeDiagnosingMatcherSubclasses should implement this. The item will already have been checked for the specific type and will never be null.- Specified by:
matchesSafelyin classTypeSafeDiagnosingMatcher<Node>
-
describeTo
Description copied from interface:SelfDescribingGenerates a description of the object. The description may be part of a a description of a larger object of which this is just a component, so it should be worded appropriately.- Parameters:
description- The description to be built or appended to.
-
evaluated
-
nodeExists
-
compiledXPath
private static XPathExpression compiledXPath(String xPathExpression, NamespaceContext namespaceContext) -
hasXPath
Creates a matcher ofNodes that matches when the examined node has a value at the specifiedxPaththat satisfies the specifiedvalueMatcher. 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 ofNodes that matches when the examined node has a value at the specifiedxPath, within the specifiednamespaceContext, that satisfies the specifiedvalueMatcher. 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
Creates a matcher ofNodes that matches when the examined node contains a node at the specifiedxPath, with any content. For example:assertThat(xml, hasXPath("/root/something[2]/cheese"))- Parameters:
xPath- the target xpath
-
hasXPath
Creates a matcher ofNodes that matches when the examined node contains a node at the specifiedxPathwithin 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
-