Skip to content

Commit a28511c

Browse files
committed
Polish Jaxb2MarshallerTests
1 parent 668b938 commit a28511c

File tree

1 file changed

+34
-46
lines changed

1 file changed

+34
-46
lines changed

spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@
7878
* @author Biju Kunjummen
7979
* @author Sam Brannen
8080
*/
81-
public class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshaller> {
81+
class Jaxb2MarshallerTests extends AbstractMarshallerTests<Jaxb2Marshaller> {
8282

8383
private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb.test";
8484

@@ -104,7 +104,7 @@ protected Object createFlights() {
104104

105105

106106
@Test
107-
public void marshalSAXResult() throws Exception {
107+
void marshalSAXResult() throws Exception {
108108
ContentHandler contentHandler = mock(ContentHandler.class);
109109
SAXResult result = new SAXResult(contentHandler);
110110
marshaller.marshal(flights, result);
@@ -124,7 +124,7 @@ public void marshalSAXResult() throws Exception {
124124
}
125125

126126
@Test
127-
public void lazyInit() throws Exception {
127+
void lazyInit() throws Exception {
128128
marshaller = new Jaxb2Marshaller();
129129
marshaller.setContextPath(CONTEXT_PATH);
130130
marshaller.setLazyInit(true);
@@ -137,56 +137,52 @@ public void lazyInit() throws Exception {
137137
}
138138

139139
@Test
140-
public void properties() throws Exception {
140+
void properties() throws Exception {
141141
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
142142
marshaller.setContextPath(CONTEXT_PATH);
143143
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));
146145
marshaller.afterPropertiesSet();
147146
}
148147

149148
@Test
150-
public void noContextPathOrClassesToBeBound() throws Exception {
149+
void noContextPathOrClassesToBeBound() throws Exception {
151150
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
152-
assertThatIllegalArgumentException().isThrownBy(
153-
marshaller::afterPropertiesSet);
151+
assertThatIllegalArgumentException().isThrownBy(marshaller::afterPropertiesSet);
154152
}
155153

156154
@Test
157-
public void testInvalidContextPath() throws Exception {
155+
void testInvalidContextPath() throws Exception {
158156
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
159157
marshaller.setContextPath("ab");
160-
assertThatExceptionOfType(UncategorizedMappingException.class).isThrownBy(
161-
marshaller::afterPropertiesSet);
158+
assertThatExceptionOfType(UncategorizedMappingException.class).isThrownBy(marshaller::afterPropertiesSet);
162159
}
163160

164161
@Test
165-
public void marshalInvalidClass() throws Exception {
162+
void marshalInvalidClass() throws Exception {
166163
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
167164
marshaller.setClassesToBeBound(FlightType.class);
168165
marshaller.afterPropertiesSet();
169166
Result result = new StreamResult(new StringWriter());
170167
Flights flights = new Flights();
171-
assertThatExceptionOfType(XmlMappingException.class).isThrownBy(() ->
172-
marshaller.marshal(flights, result));
168+
assertThatExceptionOfType(XmlMappingException.class).isThrownBy(() -> marshaller.marshal(flights, result));
173169
}
174170

175171
@Test
176-
public void supportsContextPath() throws Exception {
172+
void supportsContextPath() throws Exception {
177173
testSupports();
178174
}
179175

180176
@Test
181-
public void supportsClassesToBeBound() throws Exception {
177+
void supportsClassesToBeBound() throws Exception {
182178
marshaller = new Jaxb2Marshaller();
183179
marshaller.setClassesToBeBound(Flights.class, FlightType.class);
184180
marshaller.afterPropertiesSet();
185181
testSupports();
186182
}
187183

188184
@Test
189-
public void supportsPackagesToScan() throws Exception {
185+
void supportsPackagesToScan() throws Exception {
190186
marshaller = new Jaxb2Marshaller();
191187
marshaller.setPackagesToScan(CONTEXT_PATH);
192188
marshaller.afterPropertiesSet();
@@ -224,11 +220,11 @@ private void testSupports() throws Exception {
224220

225221
private void testSupportsPrimitives() {
226222
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 -> {
230224
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();
232228
try {
233229
// make sure the marshalling does not result in errors
234230
Object returnValue = method.invoke(primitives);
@@ -237,22 +233,18 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
237233
catch (InvocationTargetException e) {
238234
throw new AssertionError(e.getMessage(), e);
239235
}
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+
);
247239
}
248240

249241
private void testSupportsStandardClasses() throws Exception {
250242
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 -> {
254244
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();
256248
try {
257249
// make sure the marshalling does not result in errors
258250
Object returnValue = method.invoke(standardClasses);
@@ -261,17 +253,13 @@ public void doWith(Method method) throws IllegalArgumentException, IllegalAccess
261253
catch (InvocationTargetException e) {
262254
throw new AssertionError(e.getMessage(), e);
263255
}
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+
);
271259
}
272260

273261
@Test
274-
public void supportsXmlRootElement() throws Exception {
262+
void supportsXmlRootElement() throws Exception {
275263
marshaller = new Jaxb2Marshaller();
276264
marshaller.setClassesToBeBound(DummyRootElement.class, DummyType.class);
277265
marshaller.afterPropertiesSet();
@@ -284,7 +272,7 @@ public void supportsXmlRootElement() throws Exception {
284272

285273

286274
@Test
287-
public void marshalAttachments() throws Exception {
275+
void marshalAttachments() throws Exception {
288276
marshaller = new Jaxb2Marshaller();
289277
marshaller.setClassesToBeBound(BinaryObject.class);
290278
marshaller.setMtomEnabled(true);
@@ -304,7 +292,7 @@ public void marshalAttachments() throws Exception {
304292
}
305293

306294
@Test // SPR-10714
307-
public void marshalAWrappedObjectHoldingAnXmlElementDeclElement() throws Exception {
295+
void marshalAWrappedObjectHoldingAnXmlElementDeclElement() throws Exception {
308296
marshaller = new Jaxb2Marshaller();
309297
marshaller.setPackagesToScan("org.springframework.oxm.jaxb");
310298
marshaller.afterPropertiesSet();
@@ -318,7 +306,7 @@ public void marshalAWrappedObjectHoldingAnXmlElementDeclElement() throws Excepti
318306
}
319307

320308
@Test // SPR-10806
321-
public void unmarshalStreamSourceWithXmlOptions() throws Exception {
309+
void unmarshalStreamSourceWithXmlOptions() throws Exception {
322310
final javax.xml.bind.Unmarshaller unmarshaller = mock(javax.xml.bind.Unmarshaller.class);
323311
Jaxb2Marshaller marshaller = new Jaxb2Marshaller() {
324312
@Override
@@ -352,7 +340,7 @@ public javax.xml.bind.Unmarshaller createUnmarshaller() {
352340
}
353341

354342
@Test // SPR-10806
355-
public void unmarshalSaxSourceWithXmlOptions() throws Exception {
343+
void unmarshalSaxSourceWithXmlOptions() throws Exception {
356344
final javax.xml.bind.Unmarshaller unmarshaller = mock(javax.xml.bind.Unmarshaller.class);
357345
Jaxb2Marshaller marshaller = new Jaxb2Marshaller() {
358346
@Override

0 commit comments

Comments
 (0)