9
9
10
10
import javax .xml .namespace .NamespaceContext ;
11
11
import javax .xml .namespace .QName ;
12
- import javax .xml .xpath .*;
12
+ import javax .xml .xpath .XPath ;
13
+ import javax .xml .xpath .XPathExpression ;
14
+ import javax .xml .xpath .XPathExpressionException ;
15
+ import javax .xml .xpath .XPathFactory ;
13
16
14
17
import static javax .xml .xpath .XPathConstants .STRING ;
15
18
import static org .hamcrest .Condition .matched ;
23
26
*/
24
27
public class HasXPath extends TypeSafeDiagnosingMatcher <Node > {
25
28
public static final NamespaceContext NO_NAMESPACE_CONTEXT = null ;
26
- private static final IsAnything <String > WITH_ANY_CONTENT = new IsAnything <>("" );
29
+ public static final IsAnything <String > WITH_ANY_CONTENT = new IsAnything <>("" );
27
30
private static final Condition .Step <Object ,String > NODE_EXISTS = nodeExists ();
28
31
private final Matcher <String > valueMatcher ;
29
32
private final XPathExpression compiledXPath ;
@@ -49,7 +52,7 @@ public HasXPath(String xPathExpression, NamespaceContext namespaceContext, Match
49
52
this (xPathExpression , namespaceContext , valueMatcher , STRING );
50
53
}
51
54
52
- private HasXPath (String xPathExpression , NamespaceContext namespaceContext , Matcher <String > valueMatcher , QName mode ) {
55
+ public HasXPath (String xPathExpression , NamespaceContext namespaceContext , Matcher <String > valueMatcher , QName mode ) {
53
56
this .compiledXPath = compiledXPath (xPathExpression , namespaceContext );
54
57
this .xpathString = xPathExpression ;
55
58
this .valueMatcher = valueMatcher ;
@@ -104,66 +107,4 @@ private static XPathExpression compiledXPath(String xPathExpression, NamespaceCo
104
107
throw new IllegalArgumentException ("Invalid XPath : " + xPathExpression , e );
105
108
}
106
109
}
107
-
108
-
109
- /**
110
- * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node has a value at the
111
- * specified <code>xPath</code> that satisfies the specified <code>valueMatcher</code>.
112
- * For example:
113
- * <pre>assertThat(xml, hasXPath("/root/something[2]/cheese", equalTo("Cheddar")))</pre>
114
- *
115
- * @param xPath
116
- * the target xpath
117
- * @param valueMatcher
118
- * matcher for the value at the specified xpath
119
- */
120
- public static Matcher <Node > hasXPath (String xPath , Matcher <String > valueMatcher ) {
121
- return hasXPath (xPath , NO_NAMESPACE_CONTEXT , valueMatcher );
122
- }
123
-
124
- /**
125
- * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node has a value at the
126
- * specified <code>xPath</code>, within the specified <code>namespaceContext</code>, that satisfies
127
- * the specified <code>valueMatcher</code>.
128
- * For example:
129
- * <pre>assertThat(xml, hasXPath("/root/something[2]/cheese", myNs, equalTo("Cheddar")))</pre>
130
- *
131
- * @param xPath
132
- * the target xpath
133
- * @param namespaceContext
134
- * the namespace for matching nodes
135
- * @param valueMatcher
136
- * matcher for the value at the specified xpath
137
- */
138
- public static Matcher <Node > hasXPath (String xPath , NamespaceContext namespaceContext , Matcher <String > valueMatcher ) {
139
- return new HasXPath (xPath , namespaceContext , valueMatcher , STRING );
140
- }
141
-
142
- /**
143
- * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node contains a node
144
- * at the specified <code>xPath</code>, with any content.
145
- * For example:
146
- * <pre>assertThat(xml, hasXPath("/root/something[2]/cheese"))</pre>
147
- *
148
- * @param xPath
149
- * the target xpath
150
- */
151
- public static Matcher <Node > hasXPath (String xPath ) {
152
- return hasXPath (xPath , NO_NAMESPACE_CONTEXT );
153
- }
154
-
155
- /**
156
- * Creates a matcher of {@link org.w3c.dom.Node}s that matches when the examined node contains a node
157
- * at the specified <code>xPath</code> within the specified namespace context, with any content.
158
- * For example:
159
- * <pre>assertThat(xml, hasXPath("/root/something[2]/cheese", myNs))</pre>
160
- *
161
- * @param xPath
162
- * the target xpath
163
- * @param namespaceContext
164
- * the namespace for matching nodes
165
- */
166
- public static Matcher <Node > hasXPath (String xPath , NamespaceContext namespaceContext ) {
167
- return new HasXPath (xPath , namespaceContext , WITH_ANY_CONTENT , XPathConstants .NODE );
168
- }
169
110
}
0 commit comments