4040
4141import static org .assertj .core .api .Assertions .assertThat ;
4242import 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 ;
4444import static org .assertj .core .api .InstanceOfAssertFactories .array ;
4545import static org .springframework .expression .spel .support .ReflectionHelper .ArgumentsMatchKind .CLOSE ;
4646import static org .springframework .expression .spel .support .ReflectionHelper .ArgumentsMatchKind .EXACT ;
@@ -252,34 +252,42 @@ void convertAllArguments() throws Exception {
252252 checkArguments (args , "3" , null , "3.0" );
253253 }
254254
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+
255267 @ Test
256268 void setupArgumentsForVarargsInvocation () {
257269 Object [] newArray ;
258270
259- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
260- new Class <?>[] {String [].class }, "a" , "b" , "c" );
271+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { String [].class }, "a" , "b" , "c" );
261272 assertThat (newArray )
262273 .singleElement ()
263274 .asInstanceOf (array (String [].class ))
264275 .containsExactly ("a" , "b" , "c" );
265276
266- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
267- new Class <?>[] { Object [].class }, "a" , "b" , "c" );
277+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { Object [].class }, "a" , "b" , "c" );
268278 assertThat (newArray )
269279 .singleElement ()
270280 .asInstanceOf (array (Object [].class ))
271281 .containsExactly ("a" , "b" , "c" );
272282
273283 newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
274284 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" ));
280289
281- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
282- new Class <?>[] { String [].class });
290+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { String [].class });
283291 assertThat (newArray )
284292 .singleElement ()
285293 .asInstanceOf (array (String [].class ))
@@ -299,30 +307,18 @@ void setupArgumentsForVarargsInvocation() {
299307 .asInstanceOf (array (Object [].class ))
300308 .containsExactly ("a" , "b" , "c" );
301309
302- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
303- new Class <?>[] { String [].class }, "a" );
310+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { String [].class }, "a" );
304311 assertThat (newArray )
305312 .singleElement ()
306313 .asInstanceOf (array (String [].class ))
307314 .containsExactly ("a" );
308315
309-
310- newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (
311- new Class <?>[] { String [].class }, new Object []{null });
316+ newArray = ReflectionHelper .setupArgumentsForVarargsInvocation (new Class <?>[] { String [].class }, new Object [] { null });
312317 assertThat (newArray )
313318 .singleElement ()
314319 .asInstanceOf (array (String [].class ))
315320 .singleElement ()
316321 .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" );
326322 }
327323
328324 @ Test
0 commit comments