16
16
17
17
package org .springframework .oxm .xstream ;
18
18
19
- import com .thoughtworks .xstream .converters .Converter ;
19
+ import java .io .ByteArrayOutputStream ;
20
+ import java .io .Reader ;
21
+ import java .io .StringReader ;
22
+ import java .io .StringWriter ;
23
+ import java .io .Writer ;
24
+ import java .util .Arrays ;
25
+ import java .util .Collections ;
26
+ import java .util .HashMap ;
27
+ import java .util .Map ;
28
+ import java .util .concurrent .atomic .AtomicInteger ;
29
+ import javax .xml .parsers .DocumentBuilder ;
30
+ import javax .xml .parsers .DocumentBuilderFactory ;
31
+ import javax .xml .stream .XMLEventWriter ;
32
+ import javax .xml .stream .XMLOutputFactory ;
33
+ import javax .xml .stream .XMLStreamWriter ;
34
+ import javax .xml .transform .Result ;
35
+ import javax .xml .transform .Source ;
36
+ import javax .xml .transform .dom .DOMResult ;
37
+ import javax .xml .transform .sax .SAXResult ;
38
+ import javax .xml .transform .stream .StreamResult ;
39
+ import javax .xml .transform .stream .StreamSource ;
40
+
20
41
import com .thoughtworks .xstream .converters .extended .EncodedByteArrayConverter ;
21
42
import com .thoughtworks .xstream .io .HierarchicalStreamWriter ;
22
43
import com .thoughtworks .xstream .io .json .JettisonMappedXmlDriver ;
26
47
import org .junit .Ignore ;
27
48
import org .junit .Test ;
28
49
import org .mockito .InOrder ;
29
- import org .springframework .util .xml .StaxUtils ;
30
50
import org .w3c .dom .Document ;
31
51
import org .w3c .dom .Element ;
32
52
import org .w3c .dom .Node ;
36
56
import org .xmlunit .builder .Input ;
37
57
import org .xmlunit .xpath .JAXPXPathEngine ;
38
58
39
- import javax .xml .parsers .DocumentBuilder ;
40
- import javax .xml .parsers .DocumentBuilderFactory ;
41
- import javax .xml .stream .XMLEventWriter ;
42
- import javax .xml .stream .XMLOutputFactory ;
43
- import javax .xml .stream .XMLStreamWriter ;
44
- import javax .xml .transform .Result ;
45
- import javax .xml .transform .Source ;
46
- import javax .xml .transform .dom .DOMResult ;
47
- import javax .xml .transform .sax .SAXResult ;
48
- import javax .xml .transform .stream .StreamResult ;
49
- import javax .xml .transform .stream .StreamSource ;
50
- import java .io .ByteArrayOutputStream ;
51
- import java .io .Reader ;
52
- import java .io .StringReader ;
53
- import java .io .StringWriter ;
54
- import java .io .Writer ;
55
- import java .util .Arrays ;
56
- import java .util .Collections ;
57
- import java .util .HashMap ;
58
- import java .util .Map ;
59
- import java .util .concurrent .atomic .AtomicInteger ;
59
+ import org .springframework .util .xml .StaxUtils ;
60
60
61
- import static org .junit .Assert .assertEquals ;
62
- import static org .junit .Assert .assertNotNull ;
63
- import static org .junit .Assert .assertThat ;
64
- import static org .junit .Assert .assertTrue ;
65
- import static org .mockito .BDDMockito .eq ;
66
- import static org .mockito .BDDMockito .inOrder ;
67
- import static org .mockito .BDDMockito .isA ;
68
- import static org .mockito .BDDMockito .mock ;
69
- import static org .xmlunit .matchers .CompareMatcher .isSimilarTo ;
61
+ import static org .junit .Assert .*;
62
+ import static org .mockito .BDDMockito .*;
63
+ import static org .xmlunit .matchers .CompareMatcher .*;
70
64
71
65
/**
72
66
* @author Arjen Poutsma
@@ -80,8 +74,9 @@ public class XStreamMarshallerTests {
80
74
81
75
private Flight flight ;
82
76
77
+
83
78
@ Before
84
- public void createMarshaller () throws Exception {
79
+ public void createMarshaller () {
85
80
marshaller = new XStreamMarshaller ();
86
81
Map <String , String > aliases = new HashMap <>();
87
82
aliases .put ("flight" , Flight .class .getName ());
@@ -90,6 +85,7 @@ public void createMarshaller() throws Exception {
90
85
flight .setFlightNumber (42L );
91
86
}
92
87
88
+
93
89
@ Test
94
90
public void marshalDOMResult () throws Exception {
95
91
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory .newInstance ();
@@ -190,7 +186,7 @@ public void marshalStaxResultXMLEventWriter() throws Exception {
190
186
191
187
@ Test
192
188
public void converters () throws Exception {
193
- marshaller .setConverters (new Converter []{ new EncodedByteArrayConverter ()} );
189
+ marshaller .setConverters (new EncodedByteArrayConverter ());
194
190
byte [] buf = new byte []{0x1 , 0x2 };
195
191
Writer writer = new StringWriter ();
196
192
marshaller .marshal (buf , new StreamResult (writer ));
@@ -229,8 +225,7 @@ public void useAttributesForClassStringMap() throws Exception {
229
225
230
226
@ Test
231
227
public void useAttributesForClassStringListMap () throws Exception {
232
- marshaller
233
- .setUseAttributeFor (Collections .singletonMap (Flight .class , Collections .singletonList ("flightNumber" )));
228
+ marshaller .setUseAttributeFor (Collections .singletonMap (Flight .class , Collections .singletonList ("flightNumber" )));
234
229
Writer writer = new StringWriter ();
235
230
marshaller .marshal (flight , new StreamResult (writer ));
236
231
String expected = "<flight flightNumber=\" 42\" />" ;
@@ -349,6 +344,7 @@ public void annotatedMarshalStreamResultWriter() throws Exception {
349
344
assertThat ("Marshaller writes invalid StreamResult" , writer .toString (), isSimilarTo (expected ));
350
345
}
351
346
347
+
352
348
private static void assertXpathExists (String xPathExpression , String inXMLString ){
353
349
Source source = Input .fromString (inXMLString ).build ();
354
350
Iterable <Node > nodes = new JAXPXPathEngine ().selectNodes (xPathExpression , source );
0 commit comments