1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .test .util ;
18
18
19
- import static org .springframework .test .util .MatcherAssertionErrors .assertThat ;
20
-
21
19
import java .io .StringReader ;
22
20
import java .util .Map ;
23
-
24
21
import javax .xml .parsers .DocumentBuilder ;
25
22
import javax .xml .parsers .DocumentBuilderFactory ;
26
23
import javax .xml .transform .Source ;
29
26
import org .custommonkey .xmlunit .Diff ;
30
27
import org .custommonkey .xmlunit .XMLUnit ;
31
28
import org .hamcrest .Matcher ;
32
- import org .springframework .test .web .servlet .result .MockMvcResultMatchers ;
33
29
import org .w3c .dom .Document ;
34
30
import org .w3c .dom .Node ;
35
31
import org .xml .sax .InputSource ;
36
32
33
+ import static org .springframework .test .util .MatcherAssertionErrors .*;
34
+
37
35
/**
38
36
* A helper class for assertions on XML content.
39
37
*
42
40
*/
43
41
public class XmlExpectationsHelper {
44
42
45
-
46
43
/**
47
44
* Parse the content as {@link Node} and apply a {@link Matcher}.
48
45
*/
@@ -56,8 +53,7 @@ private Document parseXmlString(String xml) throws Exception {
56
53
factory .setNamespaceAware (true );
57
54
DocumentBuilder documentBuilder = factory .newDocumentBuilder ();
58
55
InputSource inputSource = new InputSource (new StringReader (xml ));
59
- Document document = documentBuilder .parse (inputSource );
60
- return document ;
56
+ return documentBuilder .parse (inputSource );
61
57
}
62
58
63
59
/**
@@ -73,18 +69,14 @@ public void assertSource(String content, Matcher<? super Source> matcher) throws
73
69
* Parse the expected and actual content strings as XML and assert that the
74
70
* two are "similar" -- i.e. they contain the same elements and attributes
75
71
* regardless of order.
76
- *
77
72
* <p>Use of this method assumes the
78
73
* <a href="http://xmlunit.sourceforge.net/">XMLUnit<a/> library is available.
79
- *
80
74
* @param expected the expected XML content
81
75
* @param actual the actual XML content
82
- *
83
- * @see MockMvcResultMatchers#xpath(String, Object...)
84
- * @see MockMvcResultMatchers#xpath(String, Map, Object...)
76
+ * @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Object...)
77
+ * @see org.springframework.test.web.servlet.result.MockMvcResultMatchers#xpath(String, Map, Object...)
85
78
*/
86
79
public void assertXmlEqual (String expected , String actual ) throws Exception {
87
-
88
80
XMLUnit .setIgnoreWhitespace (true );
89
81
XMLUnit .setIgnoreComments (true );
90
82
XMLUnit .setIgnoreAttributeOrder (true );
0 commit comments