1
1
/*
2
- * Copyright 2002-2019 the original author or authors.
2
+ * Copyright 2002-2022 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.
17
17
package org .springframework .integration .transformer ;
18
18
19
19
import static org .assertj .core .api .Assertions .assertThat ;
20
+ import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
20
21
21
22
import java .io .IOException ;
22
23
import java .math .BigDecimal ;
28
29
import java .util .Map ;
29
30
import java .util .Objects ;
30
31
31
- import org .junit .Test ;
32
+ import org .junit .jupiter .api .Disabled ;
33
+ import org .junit .jupiter .api .Test ;
32
34
33
35
import org .springframework .context .expression .MapAccessor ;
34
36
import org .springframework .expression .Expression ;
@@ -55,7 +57,7 @@ public class ObjectToMapTransformerTests {
55
57
56
58
@ SuppressWarnings ("unchecked" )
57
59
@ Test
58
- public void testObjectToSpelMapTransformer () throws IOException {
60
+ public void testObjectToSpelMapTransformer () {
59
61
Employee employee = this .buildEmployee ();
60
62
StandardEvaluationContext context = new StandardEvaluationContext ();
61
63
context .addPropertyAccessor (new MapAccessor ());
@@ -68,9 +70,9 @@ public void testObjectToSpelMapTransformer() throws IOException {
68
70
Map <String , Object > transformedMap = (Map <String , Object >) transformedMessage .getPayload ();
69
71
assertThat (transformedMap ).isNotNull ();
70
72
71
- Object valueFromTheMap = null ;
72
- Object valueFromExpression = null ;
73
- Expression expression = null ;
73
+ Object valueFromTheMap ;
74
+ Object valueFromExpression ;
75
+ Expression expression ;
74
76
75
77
expression = parser .parseExpression ("departments[0]" );
76
78
valueFromTheMap = transformedMap .get ("departments[0]" );
@@ -149,7 +151,8 @@ public void testObjectToSpelMapTransformer() throws IOException {
149
151
assertThat (valueFromExpression ).isEqualTo (valueFromTheMap );
150
152
}
151
153
152
- @ Test (expected = MessageTransformationException .class )
154
+ @ Disabled ("StackOverflowError" )
155
+ @ Test
153
156
public void testObjectToSpelMapTransformerWithCycle () {
154
157
Employee employee = this .buildEmployee ();
155
158
Child child = new Child ();
@@ -158,11 +161,13 @@ public void testObjectToSpelMapTransformerWithCycle() {
158
161
child .setParent (parent );
159
162
ObjectToMapTransformer transformer = new ObjectToMapTransformer ();
160
163
Message <Employee > message = MessageBuilder .withPayload (employee ).build ();
161
- transformer .transform (message );
164
+ assertThatExceptionOfType (MessageTransformationException .class )
165
+ .isThrownBy (() -> transformer .transform (message ))
166
+ .withRootCauseInstanceOf (StackOverflowError .class );
162
167
}
163
168
164
169
@ Test
165
- public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntryForInstantField () throws Exception {
170
+ public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntryForInstantField () {
166
171
Person person = new Person ();
167
172
person .deathDate = Instant .now ();
168
173
@@ -172,12 +177,12 @@ public void testJacksonJSR310Support_PassInstantField_ReturnsMapWithOnlyOneEntry
172
177
Map <String , Object > transformedMap = new ObjectToMapTransformer ().transformPayload (employee );
173
178
174
179
// If JSR310 support is enabled by calling findAndRegisterModules() on the Jackson mapper,
175
- // Instant field should not be broken. Thus the count should exactly be 1 here.
180
+ // Instant field should not be broken. Therefore, the count should exactly be 1 here.
176
181
assertThat (transformedMap .values ().stream ().filter (Objects ::nonNull ).count ()).isEqualTo (1L );
177
182
}
178
183
179
184
@ Test
180
- public void testCustomMapperSupport_DisableTimestampFlag_SerializesDateAsString () throws Exception {
185
+ public void testCustomMapperSupport_DisableTimestampFlag_SerializesDateAsString () {
181
186
Employee employee = buildEmployee ();
182
187
183
188
ObjectMapper customMapper = new ObjectMapper ();
@@ -203,20 +208,20 @@ public Employee buildEmployee() {
203
208
companyAddress .setStreet ("1123 Main" );
204
209
companyAddress .setZip ("12345" );
205
210
206
- Map <String , Long []> coordinates = new HashMap <String , Long [] >();
207
- coordinates .put ("latitude" , new Long [] { (long ) 1 , (long ) 5 , (long ) 13 });
208
- coordinates .put ("longitude" , new Long [] { (long ) 156 });
211
+ Map <String , Long []> coordinates = new HashMap <>();
212
+ coordinates .put ("latitude" , new Long []{ (long ) 1 , (long ) 5 , (long ) 13 });
213
+ coordinates .put ("longitude" , new Long []{ (long ) 156 });
209
214
companyAddress .setCoordinates (coordinates );
210
215
211
- List <Date > datesA = new ArrayList <Date >();
216
+ List <Date > datesA = new ArrayList <>();
212
217
datesA .add (new Date (System .currentTimeMillis () + 10000 ));
213
218
datesA .add (new Date (System .currentTimeMillis () + 20000 ));
214
219
215
- List <Date > datesB = new ArrayList <Date >();
220
+ List <Date > datesB = new ArrayList <>();
216
221
datesB .add (new Date (System .currentTimeMillis () + 30000 ));
217
222
datesB .add (new Date (System .currentTimeMillis () + 40000 ));
218
223
219
- List <List <Date >> listOfDates = new ArrayList <List < Date > >();
224
+ List <List <Date >> listOfDates = new ArrayList <>();
220
225
listOfDates .add (datesA );
221
226
listOfDates .add (datesB );
222
227
@@ -238,31 +243,31 @@ public Employee buildEmployee() {
238
243
Address personAddress = new Address ();
239
244
personAddress .setCity ("Philly" );
240
245
personAddress .setStreet ("123 Main" );
241
- List <String > listTestData = new ArrayList <String >();
246
+ List <String > listTestData = new ArrayList <>();
242
247
listTestData .add ("hello" );
243
248
listTestData .add ("blah" );
244
- Map <String , List <String >> mapWithListTestData = new HashMap <String , List < String > >();
249
+ Map <String , List <String >> mapWithListTestData = new HashMap <>();
245
250
mapWithListTestData .put ("mapWithListTestData" , listTestData );
246
251
personAddress .setMapWithListData (mapWithListTestData );
247
252
person .setAddress (personAddress );
248
253
249
- Map <String , Object > remarksA = new HashMap <String , Object >();
250
- Map <String , Object > remarksB = new HashMap <String , Object >();
254
+ Map <String , Object > remarksA = new HashMap <>();
255
+ Map <String , Object > remarksB = new HashMap <>();
251
256
remarksA .put ("foo" , "foo" );
252
257
remarksA .put ("bar" , "bar" );
253
258
remarksB .put ("baz" , "baz" );
254
- List <Map <String , Object >> remarks = new ArrayList <Map < String , Object > >();
259
+ List <Map <String , Object >> remarks = new ArrayList <>();
255
260
remarks .add (remarksA );
256
261
remarks .add (remarksB );
257
262
person .setRemarks (remarks );
258
263
employee .setPerson (person );
259
264
260
- Map <String , Map <String , Object >> testMapData = new HashMap <String , Map < String , Object > >();
265
+ Map <String , Map <String , Object >> testMapData = new HashMap <>();
261
266
262
- Map <String , Object > internalMapA = new HashMap <String , Object >();
267
+ Map <String , Object > internalMapA = new HashMap <>();
263
268
internalMapA .put ("foo" , "foo" );
264
269
internalMapA .put ("bar" , "bar" );
265
- Map <String , Object > internalMapB = new HashMap <String , Object >();
270
+ Map <String , Object > internalMapB = new HashMap <>();
266
271
internalMapB .put ("baz" , "baz" );
267
272
268
273
testMapData .put ("internalMapA" , internalMapA );
0 commit comments