Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -56,8 +56,7 @@ public class XpathExpectationsHelper {
|
||||
|
||||
|
||||
/**
|
||||
* Class constructor.
|
||||
*
|
||||
* XpathExpectationsHelper constructor.
|
||||
* @param expression the XPath expression
|
||||
* @param namespaces XML namespaces referenced in the XPath expression, or {@code null}
|
||||
* @param args arguments to parameterize the XPath expression with using the
|
||||
@@ -72,6 +71,7 @@ public class XpathExpectationsHelper {
|
||||
this.hasNamespaces = !CollectionUtils.isEmpty(namespaces);
|
||||
}
|
||||
|
||||
|
||||
private XPathExpression compileXpathExpression(String expression, Map<String, String> namespaces)
|
||||
throws XPathExpressionException {
|
||||
|
||||
@@ -83,17 +83,17 @@ public class XpathExpectationsHelper {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the compiled XPath expression.
|
||||
* Return the compiled XPath expression.
|
||||
*/
|
||||
protected XPathExpression getXpathExpression() {
|
||||
return this.xpathExpression;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the content, evaluate the XPath expression as a {@link Node}, and
|
||||
* assert it with the given {@code Matcher<Node>}.
|
||||
* Parse the content, evaluate the XPath expression as a {@link Node},
|
||||
* and assert it with the given {@code Matcher<Node>}.
|
||||
*/
|
||||
public void assertNode(String content, final Matcher<? super Node> matcher) throws Exception {
|
||||
public void assertNode(String content, Matcher<? super Node> matcher) throws Exception {
|
||||
Document document = parseXmlString(content);
|
||||
Node node = evaluateXpath(document, XPathConstants.NODE, Node.class);
|
||||
assertThat("XPath " + this.expression, node, matcher);
|
||||
@@ -101,18 +101,15 @@ public class XpathExpectationsHelper {
|
||||
|
||||
/**
|
||||
* Parse the given XML content to a {@link Document}.
|
||||
*
|
||||
* @param xml the content to parse
|
||||
* @return the parsed document
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
protected Document parseXmlString(String xml) throws Exception {
|
||||
protected Document parseXmlString(String xml) throws Exception {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
factory.setNamespaceAware(this.hasNamespaces);
|
||||
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
|
||||
InputSource inputSource = new InputSource(new StringReader(xml));
|
||||
Document document = documentBuilder.parse(inputSource);
|
||||
return document;
|
||||
return documentBuilder.parse(inputSource);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +146,6 @@ public class XpathExpectationsHelper {
|
||||
/**
|
||||
* Apply the XPath expression and assert the resulting content with the
|
||||
* given Hamcrest matcher.
|
||||
*
|
||||
* @throws Exception if content parsing or expression evaluation fails
|
||||
*/
|
||||
public void assertNodeCount(String content, Matcher<Integer> matcher) throws Exception {
|
||||
@@ -171,7 +167,6 @@ public class XpathExpectationsHelper {
|
||||
/**
|
||||
* Apply the XPath expression and assert the resulting content with the
|
||||
* given Hamcrest matcher.
|
||||
*
|
||||
* @throws Exception if content parsing or expression evaluation fails
|
||||
*/
|
||||
public void assertString(String content, Matcher<? super String> matcher) throws Exception {
|
||||
@@ -193,7 +188,6 @@ public class XpathExpectationsHelper {
|
||||
/**
|
||||
* Apply the XPath expression and assert the resulting content with the
|
||||
* given Hamcrest matcher.
|
||||
*
|
||||
* @throws Exception if content parsing or expression evaluation fails
|
||||
*/
|
||||
public void assertNumber(String content, Matcher<? super Double> matcher) throws Exception {
|
||||
@@ -222,4 +216,4 @@ public class XpathExpectationsHelper {
|
||||
assertEquals("XPath " + this.expression, expectedValue, Boolean.parseBoolean(actual));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user