1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2021 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.
78
78
* @author Biju Kunjummen
79
79
* @author Sam Brannen
80
80
*/
81
- public class Jaxb2MarshallerTests extends AbstractMarshallerTests <Jaxb2Marshaller > {
81
+ class Jaxb2MarshallerTests extends AbstractMarshallerTests <Jaxb2Marshaller > {
82
82
83
83
private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb.test" ;
84
84
@@ -104,7 +104,7 @@ protected Object createFlights() {
104
104
105
105
106
106
@ Test
107
- public void marshalSAXResult () throws Exception {
107
+ void marshalSAXResult () throws Exception {
108
108
ContentHandler contentHandler = mock (ContentHandler .class );
109
109
SAXResult result = new SAXResult (contentHandler );
110
110
marshaller .marshal (flights , result );
@@ -124,7 +124,7 @@ public void marshalSAXResult() throws Exception {
124
124
}
125
125
126
126
@ Test
127
- public void lazyInit () throws Exception {
127
+ void lazyInit () throws Exception {
128
128
marshaller = new Jaxb2Marshaller ();
129
129
marshaller .setContextPath (CONTEXT_PATH );
130
130
marshaller .setLazyInit (true );
@@ -137,56 +137,52 @@ public void lazyInit() throws Exception {
137
137
}
138
138
139
139
@ Test
140
- public void properties () throws Exception {
140
+ void properties () throws Exception {
141
141
Jaxb2Marshaller marshaller = new Jaxb2Marshaller ();
142
142
marshaller .setContextPath (CONTEXT_PATH );
143
143
marshaller .setMarshallerProperties (
144
- Collections .<String , Object >singletonMap (javax .xml .bind .Marshaller .JAXB_FORMATTED_OUTPUT ,
145
- Boolean .TRUE ));
144
+ Collections .singletonMap (javax .xml .bind .Marshaller .JAXB_FORMATTED_OUTPUT , Boolean .TRUE ));
146
145
marshaller .afterPropertiesSet ();
147
146
}
148
147
149
148
@ Test
150
- public void noContextPathOrClassesToBeBound () throws Exception {
149
+ void noContextPathOrClassesToBeBound () throws Exception {
151
150
Jaxb2Marshaller marshaller = new Jaxb2Marshaller ();
152
- assertThatIllegalArgumentException ().isThrownBy (
153
- marshaller ::afterPropertiesSet );
151
+ assertThatIllegalArgumentException ().isThrownBy (marshaller ::afterPropertiesSet );
154
152
}
155
153
156
154
@ Test
157
- public void testInvalidContextPath () throws Exception {
155
+ void testInvalidContextPath () throws Exception {
158
156
Jaxb2Marshaller marshaller = new Jaxb2Marshaller ();
159
157
marshaller .setContextPath ("ab" );
160
- assertThatExceptionOfType (UncategorizedMappingException .class ).isThrownBy (
161
- marshaller ::afterPropertiesSet );
158
+ assertThatExceptionOfType (UncategorizedMappingException .class ).isThrownBy (marshaller ::afterPropertiesSet );
162
159
}
163
160
164
161
@ Test
165
- public void marshalInvalidClass () throws Exception {
162
+ void marshalInvalidClass () throws Exception {
166
163
Jaxb2Marshaller marshaller = new Jaxb2Marshaller ();
167
164
marshaller .setClassesToBeBound (FlightType .class );
168
165
marshaller .afterPropertiesSet ();
169
166
Result result = new StreamResult (new StringWriter ());
170
167
Flights flights = new Flights ();
171
- assertThatExceptionOfType (XmlMappingException .class ).isThrownBy (() ->
172
- marshaller .marshal (flights , result ));
168
+ assertThatExceptionOfType (XmlMappingException .class ).isThrownBy (() -> marshaller .marshal (flights , result ));
173
169
}
174
170
175
171
@ Test
176
- public void supportsContextPath () throws Exception {
172
+ void supportsContextPath () throws Exception {
177
173
testSupports ();
178
174
}
179
175
180
176
@ Test
181
- public void supportsClassesToBeBound () throws Exception {
177
+ void supportsClassesToBeBound () throws Exception {
182
178
marshaller = new Jaxb2Marshaller ();
183
179
marshaller .setClassesToBeBound (Flights .class , FlightType .class );
184
180
marshaller .afterPropertiesSet ();
185
181
testSupports ();
186
182
}
187
183
188
184
@ Test
189
- public void supportsPackagesToScan () throws Exception {
185
+ void supportsPackagesToScan () throws Exception {
190
186
marshaller = new Jaxb2Marshaller ();
191
187
marshaller .setPackagesToScan (CONTEXT_PATH );
192
188
marshaller .afterPropertiesSet ();
@@ -224,11 +220,11 @@ private void testSupports() throws Exception {
224
220
225
221
private void testSupportsPrimitives () {
226
222
final Primitives primitives = new Primitives ();
227
- ReflectionUtils .doWithMethods (Primitives .class , new ReflectionUtils .MethodCallback () {
228
- @ Override
229
- public void doWith (Method method ) throws IllegalArgumentException , IllegalAccessException {
223
+ ReflectionUtils .doWithMethods (Primitives .class , method -> {
230
224
Type returnType = method .getGenericReturnType ();
231
- assertThat (marshaller .supports (returnType )).as ("Jaxb2Marshaller does not support JAXBElement<" + method .getName ().substring (9 ) + ">" ).isTrue ();
225
+ assertThat (marshaller .supports (returnType ))
226
+ .as ("Jaxb2Marshaller does not support JAXBElement<" + method .getName ().substring (9 ) + ">" )
227
+ .isTrue ();
232
228
try {
233
229
// make sure the marshalling does not result in errors
234
230
Object returnValue = method .invoke (primitives );
@@ -237,22 +233,18 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
237
233
catch (InvocationTargetException e ) {
238
234
throw new AssertionError (e .getMessage (), e );
239
235
}
240
- }
241
- }, new ReflectionUtils .MethodFilter () {
242
- @ Override
243
- public boolean matches (Method method ) {
244
- return method .getName ().startsWith ("primitive" );
245
- }
246
- });
236
+ },
237
+ method -> method .getName ().startsWith ("primitive" )
238
+ );
247
239
}
248
240
249
241
private void testSupportsStandardClasses () throws Exception {
250
242
final StandardClasses standardClasses = new StandardClasses ();
251
- ReflectionUtils .doWithMethods (StandardClasses .class , new ReflectionUtils .MethodCallback () {
252
- @ Override
253
- public void doWith (Method method ) throws IllegalArgumentException , IllegalAccessException {
243
+ ReflectionUtils .doWithMethods (StandardClasses .class , method -> {
254
244
Type returnType = method .getGenericReturnType ();
255
- assertThat (marshaller .supports (returnType )).as ("Jaxb2Marshaller does not support JAXBElement<" + method .getName ().substring (13 ) + ">" ).isTrue ();
245
+ assertThat (marshaller .supports (returnType ))
246
+ .as ("Jaxb2Marshaller does not support JAXBElement<" + method .getName ().substring (13 ) + ">" )
247
+ .isTrue ();
256
248
try {
257
249
// make sure the marshalling does not result in errors
258
250
Object returnValue = method .invoke (standardClasses );
@@ -261,17 +253,13 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
261
253
catch (InvocationTargetException e ) {
262
254
throw new AssertionError (e .getMessage (), e );
263
255
}
264
- }
265
- }, new ReflectionUtils .MethodFilter () {
266
- @ Override
267
- public boolean matches (Method method ) {
268
- return method .getName ().startsWith ("standardClass" );
269
- }
270
- });
256
+ },
257
+ method -> method .getName ().startsWith ("standardClass" )
258
+ );
271
259
}
272
260
273
261
@ Test
274
- public void supportsXmlRootElement () throws Exception {
262
+ void supportsXmlRootElement () throws Exception {
275
263
marshaller = new Jaxb2Marshaller ();
276
264
marshaller .setClassesToBeBound (DummyRootElement .class , DummyType .class );
277
265
marshaller .afterPropertiesSet ();
@@ -284,7 +272,7 @@ public void supportsXmlRootElement() throws Exception {
284
272
285
273
286
274
@ Test
287
- public void marshalAttachments () throws Exception {
275
+ void marshalAttachments () throws Exception {
288
276
marshaller = new Jaxb2Marshaller ();
289
277
marshaller .setClassesToBeBound (BinaryObject .class );
290
278
marshaller .setMtomEnabled (true );
@@ -304,7 +292,7 @@ public void marshalAttachments() throws Exception {
304
292
}
305
293
306
294
@ Test // SPR-10714
307
- public void marshalAWrappedObjectHoldingAnXmlElementDeclElement () throws Exception {
295
+ void marshalAWrappedObjectHoldingAnXmlElementDeclElement () throws Exception {
308
296
marshaller = new Jaxb2Marshaller ();
309
297
marshaller .setPackagesToScan ("org.springframework.oxm.jaxb" );
310
298
marshaller .afterPropertiesSet ();
@@ -318,7 +306,7 @@ public void marshalAWrappedObjectHoldingAnXmlElementDeclElement() throws Excepti
318
306
}
319
307
320
308
@ Test // SPR-10806
321
- public void unmarshalStreamSourceWithXmlOptions () throws Exception {
309
+ void unmarshalStreamSourceWithXmlOptions () throws Exception {
322
310
final javax .xml .bind .Unmarshaller unmarshaller = mock (javax .xml .bind .Unmarshaller .class );
323
311
Jaxb2Marshaller marshaller = new Jaxb2Marshaller () {
324
312
@ Override
@@ -352,7 +340,7 @@ public javax.xml.bind.Unmarshaller createUnmarshaller() {
352
340
}
353
341
354
342
@ Test // SPR-10806
355
- public void unmarshalSaxSourceWithXmlOptions () throws Exception {
343
+ void unmarshalSaxSourceWithXmlOptions () throws Exception {
356
344
final javax .xml .bind .Unmarshaller unmarshaller = mock (javax .xml .bind .Unmarshaller .class );
357
345
Jaxb2Marshaller marshaller = new Jaxb2Marshaller () {
358
346
@ Override
0 commit comments