@@ -125,6 +125,7 @@ protected Object createFlights() {
125
125
return flights ;
126
126
}
127
127
128
+
128
129
@ Test
129
130
public void marshalSaxResult () throws Exception {
130
131
ContentHandler contentHandler = mock (ContentHandler .class );
@@ -133,13 +134,13 @@ public void marshalSaxResult() throws Exception {
133
134
InOrder ordered = inOrder (contentHandler );
134
135
ordered .verify (contentHandler ).startDocument ();
135
136
ordered .verify (contentHandler ).startPrefixMapping ("tns" , "http://samples.springframework.org/flight" );
136
- ordered .verify (contentHandler ).startElement (eq ("http://samples.springframework.org/flight" ), eq ( "flights" ),
137
- eq ("tns:flights" ), isA (Attributes .class ));
138
- ordered .verify (contentHandler ).startElement (eq ("http://samples.springframework.org/flight" ), eq ( "flight" ),
139
- eq ("tns:flight" ), isA (Attributes .class ));
140
- ordered .verify (contentHandler ).startElement (eq ("http://samples.springframework.org/flight" ), eq ( "number" ),
141
- eq ("tns:number" ), isA (Attributes .class ));
142
- ordered .verify (contentHandler ).characters (eq (new char [] { '4' , '2' }), eq (0 ), eq (2 ));
137
+ ordered .verify (contentHandler ).startElement (eq ("http://samples.springframework.org/flight" ),
138
+ eq ( "flights" ), eq ("tns:flights" ), isA (Attributes .class ));
139
+ ordered .verify (contentHandler ).startElement (eq ("http://samples.springframework.org/flight" ),
140
+ eq ( "flight" ), eq ("tns:flight" ), isA (Attributes .class ));
141
+ ordered .verify (contentHandler ).startElement (eq ("http://samples.springframework.org/flight" ),
142
+ eq ( "number" ), eq ("tns:number" ), isA (Attributes .class ));
143
+ ordered .verify (contentHandler ).characters (eq (new char []{ '4' , '2' }), eq (0 ), eq (2 ));
143
144
ordered .verify (contentHandler ).endElement ("http://samples.springframework.org/flight" , "number" , "tns:number" );
144
145
ordered .verify (contentHandler ).endElement ("http://samples.springframework.org/flight" , "flight" , "tns:flight" );
145
146
ordered .verify (contentHandler ).endElement ("http://samples.springframework.org/flight" , "flights" , "tns:flights" );
@@ -170,7 +171,6 @@ public void testSuppressNamespacesFalse() throws Exception {
170
171
@ Test
171
172
public void testSuppressXsiTypeTrue () throws Exception {
172
173
CastorObject castorObject = createCastorObject ();
173
-
174
174
getCastorMarshaller ().setSuppressXsiType (true );
175
175
getCastorMarshaller ().setRootElement ("objects" );
176
176
String result = marshal (Arrays .asList (castorObject ));
@@ -180,7 +180,6 @@ public void testSuppressXsiTypeTrue() throws Exception {
180
180
@ Test
181
181
public void testSuppressXsiTypeFalse () throws Exception {
182
182
CastorObject castorObject = createCastorObject ();
183
-
184
183
getCastorMarshaller ().setSuppressXsiType (false );
185
184
getCastorMarshaller ().setRootElement ("objects" );
186
185
String result = marshal (Arrays .asList (castorObject ));
@@ -189,17 +188,15 @@ public void testSuppressXsiTypeFalse() throws Exception {
189
188
190
189
@ Test
191
190
public void testMarshalAsDocumentTrue () throws Exception {
192
-
193
191
getCastorMarshaller ().setMarshalAsDocument (true );
194
192
String result = marshalFlights ();
195
193
assertXMLEqual ("Marshaller wrote invalid result" , DOCUMENT_EXPECTED_STRING , result );
196
194
assertTrue ("Result doesn't contain xml declaration." ,
197
- result .contains ("<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" ));
195
+ result .contains ("<?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" ));
198
196
}
199
197
200
198
@ Test
201
199
public void testMarshalAsDocumentFalse () throws Exception {
202
-
203
200
getCastorMarshaller ().setMarshalAsDocument (true );
204
201
String result = marshalFlights ();
205
202
assertXMLEqual ("Marshaller wrote invalid result" , EXPECTED_STRING , result );
@@ -208,7 +205,6 @@ public void testMarshalAsDocumentFalse() throws Exception {
208
205
209
206
@ Test
210
207
public void testRootElement () throws Exception {
211
-
212
208
getCastorMarshaller ().setRootElement ("canceledFlights" );
213
209
String result = marshalFlights ();
214
210
assertXMLEqual ("Marshaller wrote invalid result" , ROOT_ELEMENT_EXPECTED_STRING , result );
@@ -217,31 +213,26 @@ public void testRootElement() throws Exception {
217
213
@ Test
218
214
public void testNoNamespaceSchemaLocation () throws Exception {
219
215
String noNamespaceSchemaLocation = "flights.xsd" ;
220
-
221
216
getCastorMarshaller ().setNoNamespaceSchemaLocation (noNamespaceSchemaLocation );
222
217
String result = marshalFlights ();
223
-
224
218
assertXpathEvaluatesTo ("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value." ,
225
- noNamespaceSchemaLocation , "/tns:flights/@xsi:noNamespaceSchemaLocation" , result );
219
+ noNamespaceSchemaLocation , "/tns:flights/@xsi:noNamespaceSchemaLocation" , result );
226
220
assertXMLEqual ("Marshaller wrote invalid result" , EXPECTED_STRING , result );
227
221
}
228
222
229
223
@ Test
230
224
public void testSchemaLocation () throws Exception {
231
225
String schemaLocation = "flights.xsd" ;
232
-
233
226
getCastorMarshaller ().setSchemaLocation (schemaLocation );
234
227
String result = marshalFlights ();
235
-
236
228
assertXpathEvaluatesTo ("The xsi:noNamespaceSchemaLocation hasn't been written or has invalid value." ,
237
- schemaLocation , "/tns:flights/@xsi:schemaLocation" , result );
229
+ schemaLocation , "/tns:flights/@xsi:schemaLocation" , result );
238
230
assertXMLEqual ("Marshaller wrote invalid result" , EXPECTED_STRING , result );
239
231
}
240
232
241
233
@ Test
242
234
public void testUseXsiTypeAsRootTrue () throws Exception {
243
235
CastorObject castorObject = createCastorObject ();
244
-
245
236
getCastorMarshaller ().setSuppressXsiType (false );
246
237
getCastorMarshaller ().setUseXSITypeAtRoot (true );
247
238
getCastorMarshaller ().setRootElement ("objects" );
@@ -252,24 +243,22 @@ public void testUseXsiTypeAsRootTrue() throws Exception {
252
243
@ Test
253
244
public void testUseXsiTypeAsRootFalse () throws Exception {
254
245
CastorObject castorObject = createCastorObject ();
255
-
256
246
getCastorMarshaller ().setSuppressXsiType (false );
257
247
getCastorMarshaller ().setUseXSITypeAtRoot (false );
258
248
getCastorMarshaller ().setRootElement ("objects" );
259
249
String result = marshal (Arrays .asList (castorObject ));
260
250
assertXMLEqual ("Marshaller wrote invalid result" , ROOT_WITHOUT_XSI_EXPECTED_STRING , result );
261
251
}
262
252
253
+
263
254
private CastorMarshaller getCastorMarshaller () {
264
255
return (CastorMarshaller ) marshaller ;
265
256
}
266
257
267
258
private String marshal (Object object ) throws Exception {
268
-
269
259
StringWriter writer = new StringWriter ();
270
260
StreamResult result = new StreamResult (writer );
271
261
getCastorMarshaller ().marshal (object , result );
272
-
273
262
return writer .toString ();
274
263
}
275
264
@@ -278,7 +267,7 @@ private String marshalFlights() throws Exception {
278
267
}
279
268
280
269
/**
281
- * Asserts the values of xpath expression evaluation is exactly the same as expected value.
270
+ * Assert the values of xpath expression evaluation is exactly the same as expected value.
282
271
* <p>The xpath may contain the xml namespace prefixes, since namespaces from flight example
283
272
* are being registered.
284
273
* @param msg the error message that will be used in case of test failure
@@ -302,7 +291,7 @@ private void assertXpathEvaluatesTo(String msg, String expected, String xpath, S
302
291
}
303
292
304
293
/**
305
- * Creates a instance of {@link CastorObject} for testing.
294
+ * Create an instance of {@link CastorObject} for testing.
306
295
*/
307
296
private CastorObject createCastorObject () {
308
297
CastorObject castorObject = new CastorObject ();
0 commit comments