diff --git a/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java b/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java index ac1ea9fb93c..a9caf379a66 100644 --- a/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java +++ b/spring-test/src/main/java/org/springframework/test/util/XmlExpectationsHelper.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2017 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. @@ -28,7 +28,9 @@ import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.InputSource; import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.diff.DefaultNodeMatcher; import org.xmlunit.diff.Diff; +import org.xmlunit.diff.ElementSelectors; import static org.hamcrest.MatcherAssert.*; @@ -58,7 +60,7 @@ public class XmlExpectationsHelper { /** * Parse the content as {@link DOMSource} and apply a {@link Matcher}. - * @see xml-matchers + * @see xml-matchers */ public void assertSource(String content, Matcher super Source> matcher) throws Exception { Document document = parseXmlString(content); @@ -70,7 +72,7 @@ public class XmlExpectationsHelper { * two are "similar" -- i.e. they contain the same elements and attributes * regardless of order. *
Use of this method assumes the
- * XMLUnit library is available.
+ * XMLUnit library is available.
* @param expected the expected XML content
* @param actual the actual XML content
* @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Object...)
@@ -78,6 +80,7 @@ public class XmlExpectationsHelper {
*/
public void assertXmlEqual(String expected, String actual) throws Exception {
Diff diffSimilar = DiffBuilder.compare(expected).withTest(actual)
+ .withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.ignoreWhitespace().ignoreComments()
.checkForSimilar()
.build();
diff --git a/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java b/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java
new file mode 100644
index 00000000000..f4fe6f1da73
--- /dev/null
+++ b/spring-test/src/test/java/org/springframework/test/util/XmlExpectationsHelperTests.java
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2002-2017 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.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.test.util;
+
+import org.hamcrest.Matchers;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+/**
+ * Unit tests for {@link XmlExpectationsHelper}.
+ *
+ * @author Matthew Depue
+ */
+public class XmlExpectationsHelperTests {
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+
+
+ @Test
+ public void assertXmlEqualForEqual() throws Exception {
+ final String control = "