@@ -191,4 +191,66 @@ public void test() throws Exception {
191
191
}.runTest ();
192
192
}
193
193
194
+ @ Test
195
+ public void invokeMethodWithAutoboxingAndUnboxing () {
196
+ // IntelliJ IDEA 11 won't accept int assignment here
197
+ Integer difference = invokeMethod (component , "subtract" , 5 , 2 );
198
+ assertEquals ("subtract(5, 2)" , 3 , difference .intValue ());
199
+ }
200
+
201
+ @ Ignore ("[SPR-8644] findMethod() does not currently support var-args" )
202
+ @ Test
203
+ public void invokeMethodWithPrimitiveVarArgs () {
204
+ // IntelliJ IDEA 11 won't accept int assignment here
205
+ Integer sum = invokeMethod (component , "add" , 1 , 2 , 3 , 4 );
206
+ assertEquals ("add(1,2,3,4)" , 10 , sum .intValue ());
207
+ }
208
+
209
+ @ Test
210
+ public void invokeMethodWithPrimitiveVarArgsAsSingleArgument () {
211
+ // IntelliJ IDEA 11 won't accept int assignment here
212
+ Integer sum = invokeMethod (component , "add" , new int [] { 1 , 2 , 3 , 4 });
213
+ assertEquals ("add(1,2,3,4)" , 10 , sum .intValue ());
214
+ }
215
+
216
+ @ Test
217
+ public void invokeMethodsSimulatingLifecycleEvents () {
218
+ assertNull ("number" , component .getNumber ());
219
+ assertNull ("text" , component .getText ());
220
+
221
+ // Simulate autowiring a configuration method
222
+ invokeMethod (component , "configure" , new Integer (42 ), "enigma" );
223
+ assertEquals ("number should have been configured" , new Integer (42 ), component .getNumber ());
224
+ assertEquals ("text should have been configured" , "enigma" , component .getText ());
225
+
226
+ // Simulate @PostConstruct life-cycle event
227
+ invokeMethod (component , "init" );
228
+ // assertions in init() should succeed
229
+
230
+ // Simulate @PreDestroy life-cycle event
231
+ invokeMethod (component , "destroy" );
232
+ assertNull ("number" , component .getNumber ());
233
+ assertNull ("text" , component .getText ());
234
+ }
235
+
236
+ @ Test (expected = IllegalStateException .class )
237
+ public void invokeMethodWithIncompatibleArgumentTypes () {
238
+ invokeMethod (component , "subtract" , "foo" , 2.0 );
239
+ }
240
+
241
+ @ Test (expected = IllegalStateException .class )
242
+ public void invokeInitMethodBeforeAutowiring () {
243
+ invokeMethod (component , "init" );
244
+ }
245
+
246
+ @ Test (expected = IllegalStateException .class )
247
+ public void invokeMethodWithTooFewArguments () {
248
+ invokeMethod (component , "configure" , new Integer (42 ));
249
+ }
250
+
251
+ @ Test (expected = IllegalStateException .class )
252
+ public void invokeMethodWithTooManyArguments () {
253
+ invokeMethod (component , "configure" , new Integer (42 ), "enigma" , "baz" , "quux" );
254
+ }
255
+
194
256
}
0 commit comments