40
40
41
41
import static org .assertj .core .api .Assertions .assertThat ;
42
42
import static org .assertj .core .api .Assertions .assertThatExceptionOfType ;
43
- import static org .assertj .core .api .Assertions .assertThatThrownBy ;
43
+ import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
44
44
import static org .assertj .core .api .InstanceOfAssertFactories .array ;
45
45
import static org .springframework .expression .spel .support .ReflectionHelper .ArgumentsMatchKind .CLOSE ;
46
46
import static org .springframework .expression .spel .support .ReflectionHelper .ArgumentsMatchKind .EXACT ;
@@ -252,34 +252,42 @@ void convertAllArguments() throws Exception {
252
252
checkArguments (args , "3" , null , "3.0" );
253
253
}
254
254
255
+ @ Test
256
+ void setupArgumentsForVarargsInvocationPreconditions () {
257
+ assertThatIllegalArgumentException ()
258
+ .isThrownBy (() -> ReflectionHelper .setupArgumentsForVarargsInvocation (new Class [] {}, "a" ))
259
+ .withMessage ("Required parameter types array must not be empty" );
260
+
261
+ assertThatIllegalArgumentException ()
262
+ .isThrownBy (() -> ReflectionHelper .setupArgumentsForVarargsInvocation (
263
+ new Class <?>[] { Integer .class , Integer .class }, 123 ))
264
+ .withMessage ("The last required parameter type must be an array to support varargs invocation" );
265
+ }
266
+
255
267
@ Test
256
268
void setupArgumentsForVarargsInvocation () {
257
269
Object [] newArray ;
258
270
259
- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
260
- new Class <?>[] {String [].class }, "a" , "b" , "c" );
271
+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { String [].class }, "a" , "b" , "c" );
261
272
assertThat (newArray )
262
273
.singleElement ()
263
274
.asInstanceOf (array (String [].class ))
264
275
.containsExactly ("a" , "b" , "c" );
265
276
266
- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
267
- new Class <?>[] { Object [].class }, "a" , "b" , "c" );
277
+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { Object [].class }, "a" , "b" , "c" );
268
278
assertThat (newArray )
269
279
.singleElement ()
270
280
.asInstanceOf (array (Object [].class ))
271
281
.containsExactly ("a" , "b" , "c" );
272
282
273
283
newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
274
284
new Class <?>[] { Integer .class , Integer .class , String [].class }, 123 , 456 , "a" , "b" , "c" );
275
- assertThat (newArray )
276
- .satisfiesExactly (
277
- i -> assertThat (i ).isEqualTo (123 ),
278
- i -> assertThat (i ).isEqualTo (456 ),
279
- i -> assertThat (i ).asInstanceOf (array (String [].class )).containsExactly ("a" , "b" , "c" ));
285
+ assertThat (newArray ).satisfiesExactly (
286
+ one -> assertThat (one ).isEqualTo (123 ),
287
+ two -> assertThat (two ).isEqualTo (456 ),
288
+ three -> assertThat (three ).asInstanceOf (array (String [].class )).containsExactly ("a" , "b" , "c" ));
280
289
281
- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
282
- new Class <?>[] { String [].class });
290
+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { String [].class });
283
291
assertThat (newArray )
284
292
.singleElement ()
285
293
.asInstanceOf (array (String [].class ))
@@ -299,30 +307,18 @@ void setupArgumentsForVarargsInvocation() {
299
307
.asInstanceOf (array (Object [].class ))
300
308
.containsExactly ("a" , "b" , "c" );
301
309
302
- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
303
- new Class <?>[] { String [].class }, "a" );
310
+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { String [].class }, "a" );
304
311
assertThat (newArray )
305
312
.singleElement ()
306
313
.asInstanceOf (array (String [].class ))
307
314
.containsExactly ("a" );
308
315
309
-
310
- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
311
- new Class <?>[] { String [].class }, new Object []{null });
316
+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { String [].class }, new Object [] { null });
312
317
assertThat (newArray )
313
318
.singleElement ()
314
319
.asInstanceOf (array (String [].class ))
315
320
.singleElement ()
316
321
.isNull ();
317
-
318
- assertThatThrownBy (() -> ReflectionHelper .setupArgumentsForVarargsInvocation (
319
- new Class <?>[] { Integer .class , Integer .class }, 123 , 456 ))
320
- .isInstanceOf (IllegalArgumentException .class )
321
- .hasMessage ("Method must be varargs" );
322
-
323
- assertThatThrownBy (() -> ReflectionHelper .setupArgumentsForVarargsInvocation (new Class [] {}, "a" , "b" , "c" ))
324
- .isInstanceOf (IllegalArgumentException .class )
325
- .hasMessage ("Required parameter types must not be empty" );
326
322
}
327
323
328
324
@ Test
0 commit comments