Skip to content

Commit 7f0ef63

Browse files
author
smgfreeman
committed
sf minor refactoring
1 parent dec267a commit 7f0ef63

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

‎hamcrest-library/src/main/java/org/hamcrest/xml/HasXPath.java‎

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,7 @@ private HasXPath(String xPathExpression, NamespaceContext namespaceContext, Matc
6262
@Override
6363
public boolean matchesSafely(Node item, Description mismatchDescription) {
6464
try {
65-
Object result = compiledXPath.evaluate(item, evaluationMode);
66-
if (result == null) {
67-
mismatchDescription.appendText("xpath returned no results.");
68-
return false;
69-
} else if (valueMatcher == null) {
70-
return true;
71-
} else {
72-
boolean valueMatched = valueMatcher.matches(result);
73-
if (!valueMatched) {
74-
mismatchDescription.appendText("xpath result ");
75-
valueMatcher.describeMismatch(result, mismatchDescription);
76-
}
77-
return valueMatched;
78-
}
65+
return matchesResult(compiledXPath.evaluate(item, evaluationMode), mismatchDescription);
7966
} catch (XPathExpressionException e) {
8067
return false;
8168
}
@@ -88,6 +75,22 @@ public void describeTo(Description description) {
8875
}
8976
}
9077

78+
private boolean matchesResult(Object result, Description mismatchDescription) {
79+
if (result == null) {
80+
mismatchDescription.appendText("xpath returned no results.");
81+
return false;
82+
} else if (valueMatcher == null) {
83+
return true;
84+
} else {
85+
boolean valueMatched = valueMatcher.matches(result);
86+
if (!valueMatched) {
87+
mismatchDescription.appendText("xpath result ");
88+
valueMatcher.describeMismatch(result, mismatchDescription);
89+
}
90+
return valueMatched;
91+
}
92+
}
93+
9194
@Factory
9295
public static Matcher<Node> hasXPath(String xPath, Matcher<? super String> valueMatcher) {
9396
return hasXPath(xPath, null, valueMatcher);

0 commit comments

Comments
 (0)