1
1
/*
2
- * Copyright 2002-2015 the original author or authors.
2
+ * Copyright 2002-2018 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.
40
40
import org .springframework .beans .factory .config .TypedStringValue ;
41
41
import org .springframework .beans .factory .xml .XmlBeanDefinitionReader ;
42
42
import org .springframework .beans .propertyeditors .CustomNumberEditor ;
43
+ import org .springframework .core .OverridingClassLoader ;
43
44
import org .springframework .core .ResolvableType ;
44
45
import org .springframework .core .io .ClassPathResource ;
45
46
import org .springframework .core .io .UrlResource ;
@@ -65,7 +66,7 @@ public void testGenericSetProperty() {
65
66
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
66
67
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
67
68
68
- Set <String > input = new HashSet <String >();
69
+ Set <String > input = new HashSet <>();
69
70
input .add ("4" );
70
71
input .add ("5" );
71
72
rbd .getPropertyValues ().add ("integerSet" , input );
@@ -82,7 +83,7 @@ public void testGenericListProperty() throws MalformedURLException {
82
83
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
83
84
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
84
85
85
- List <String > input = new ArrayList <String >();
86
+ List <String > input = new ArrayList <>();
86
87
input .add ("http://localhost:8080" );
87
88
input .add ("http://localhost:9090" );
88
89
rbd .getPropertyValues ().add ("resourceList" , input );
@@ -114,7 +115,7 @@ public void testGenericListPropertyWithInvalidElementType() {
114
115
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
115
116
RootBeanDefinition rbd = new RootBeanDefinition (GenericIntegerBean .class );
116
117
117
- List <Integer > input = new ArrayList <Integer >();
118
+ List <Integer > input = new ArrayList <>();
118
119
input .add (1 );
119
120
rbd .getPropertyValues ().add ("testBeanList" , input );
120
121
@@ -146,7 +147,7 @@ public void testGenericMapProperty() {
146
147
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
147
148
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
148
149
149
- Map <String , String > input = new HashMap <String , String >();
150
+ Map <String , String > input = new HashMap <>();
150
151
input .put ("4" , "5" );
151
152
input .put ("6" , "7" );
152
153
rbd .getPropertyValues ().add ("shortMap" , input );
@@ -178,7 +179,7 @@ public void testGenericSetConstructor() {
178
179
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
179
180
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
180
181
181
- Set <String > input = new HashSet <String >();
182
+ Set <String > input = new HashSet <>();
182
183
input .add ("4" );
183
184
input .add ("5" );
184
185
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -222,10 +223,10 @@ public void testGenericSetListConstructor() throws MalformedURLException {
222
223
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
223
224
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
224
225
225
- Set <String > input = new HashSet <String >();
226
+ Set <String > input = new HashSet <>();
226
227
input .add ("4" );
227
228
input .add ("5" );
228
- List <String > input2 = new ArrayList <String >();
229
+ List <String > input2 = new ArrayList <>();
229
230
input2 .add ("http://localhost:8080" );
230
231
input2 .add ("http://localhost:9090" );
231
232
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -279,10 +280,10 @@ public void testGenericSetMapConstructor() throws MalformedURLException {
279
280
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
280
281
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
281
282
282
- Set <String > input = new HashSet <String >();
283
+ Set <String > input = new HashSet <>();
283
284
input .add ("4" );
284
285
input .add ("5" );
285
- Map <String , String > input2 = new HashMap <String , String >();
286
+ Map <String , String > input2 = new HashMap <>();
286
287
input2 .put ("4" , "5" );
287
288
input2 .put ("6" , "7" );
288
289
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -302,7 +303,7 @@ public void testGenericMapResourceConstructor() throws MalformedURLException {
302
303
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
303
304
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
304
305
305
- Map <String , String > input = new HashMap <String , String >();
306
+ Map <String , String > input = new HashMap <>();
306
307
input .put ("4" , "5" );
307
308
input .put ("6" , "7" );
308
309
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -321,10 +322,10 @@ public void testGenericMapMapConstructor() throws MalformedURLException {
321
322
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
322
323
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
323
324
324
- Map <String , String > input = new HashMap <String , String >();
325
+ Map <String , String > input = new HashMap <>();
325
326
input .put ("1" , "0" );
326
327
input .put ("2" , "3" );
327
- Map <String , String > input2 = new HashMap <String , String >();
328
+ Map <String , String > input2 = new HashMap <>();
328
329
input2 .put ("4" , "5" );
329
330
input2 .put ("6" , "7" );
330
331
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -347,7 +348,7 @@ public void testGenericMapMapConstructorWithSameRefAndConversion() throws Malfor
347
348
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
348
349
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
349
350
350
- Map <String , String > input = new HashMap <String , String >();
351
+ Map <String , String > input = new HashMap <>();
351
352
input .put ("1" , "0" );
352
353
input .put ("2" , "3" );
353
354
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -370,7 +371,7 @@ public void testGenericMapMapConstructorWithSameRefAndNoConversion() throws Malf
370
371
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
371
372
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
372
373
373
- Map <Short , Integer > input = new HashMap <Short , Integer >();
374
+ Map <Short , Integer > input = new HashMap <>();
374
375
input .put (new Short ((short ) 1 ), new Integer (0 ));
375
376
input .put (new Short ((short ) 2 ), new Integer (3 ));
376
377
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -390,7 +391,7 @@ public void testGenericMapWithKeyTypeConstructor() throws MalformedURLException
390
391
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
391
392
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
392
393
393
- Map <String , String > input = new HashMap <String , String >();
394
+ Map <String , String > input = new HashMap <>();
394
395
input .put ("4" , "5" );
395
396
input .put ("6" , "7" );
396
397
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -413,11 +414,11 @@ public void registerCustomEditors(PropertyEditorRegistry registry) {
413
414
});
414
415
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
415
416
416
- Map <String , AbstractCollection <?>> input = new HashMap <String , AbstractCollection <?> >();
417
- HashSet <Integer > value1 = new HashSet <Integer >();
417
+ Map <String , AbstractCollection <?>> input = new HashMap <>();
418
+ HashSet <Integer > value1 = new HashSet <>();
418
419
value1 .add (new Integer (1 ));
419
420
input .put ("1" , value1 );
420
- ArrayList <Boolean > value2 = new ArrayList <Boolean >();
421
+ ArrayList <Boolean > value2 = new ArrayList <>();
421
422
value2 .add (Boolean .TRUE );
422
423
input .put ("2" , value2 );
423
424
rbd .getConstructorArgumentValues ().addGenericArgumentValue (Boolean .TRUE );
@@ -437,7 +438,7 @@ public void testGenericSetFactoryMethod() {
437
438
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
438
439
rbd .setFactoryMethodName ("createInstance" );
439
440
440
- Set <String > input = new HashSet <String >();
441
+ Set <String > input = new HashSet <>();
441
442
input .add ("4" );
442
443
input .add ("5" );
443
444
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -455,10 +456,10 @@ public void testGenericSetListFactoryMethod() throws MalformedURLException {
455
456
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
456
457
rbd .setFactoryMethodName ("createInstance" );
457
458
458
- Set <String > input = new HashSet <String >();
459
+ Set <String > input = new HashSet <>();
459
460
input .add ("4" );
460
461
input .add ("5" );
461
- List <String > input2 = new ArrayList <String >();
462
+ List <String > input2 = new ArrayList <>();
462
463
input2 .add ("http://localhost:8080" );
463
464
input2 .add ("http://localhost:9090" );
464
465
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -479,10 +480,10 @@ public void testGenericSetMapFactoryMethod() throws MalformedURLException {
479
480
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
480
481
rbd .setFactoryMethodName ("createInstance" );
481
482
482
- Set <String > input = new HashSet <String >();
483
+ Set <String > input = new HashSet <>();
483
484
input .add ("4" );
484
485
input .add ("5" );
485
- Map <String , String > input2 = new HashMap <String , String >();
486
+ Map <String , String > input2 = new HashMap <>();
486
487
input2 .put ("4" , "5" );
487
488
input2 .put ("6" , "7" );
488
489
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -503,7 +504,7 @@ public void testGenericMapResourceFactoryMethod() throws MalformedURLException {
503
504
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
504
505
rbd .setFactoryMethodName ("createInstance" );
505
506
506
- Map <String , String > input = new HashMap <String , String >();
507
+ Map <String , String > input = new HashMap <>();
507
508
input .put ("4" , "5" );
508
509
input .put ("6" , "7" );
509
510
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -523,10 +524,10 @@ public void testGenericMapMapFactoryMethod() throws MalformedURLException {
523
524
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
524
525
rbd .setFactoryMethodName ("createInstance" );
525
526
526
- Map <String , String > input = new HashMap <String , String >();
527
+ Map <String , String > input = new HashMap <>();
527
528
input .put ("1" , "0" );
528
529
input .put ("2" , "3" );
529
- Map <String , String > input2 = new HashMap <String , String >();
530
+ Map <String , String > input2 = new HashMap <>();
530
531
input2 .put ("4" , "5" );
531
532
input2 .put ("6" , "7" );
532
533
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -547,7 +548,7 @@ public void testGenericMapWithKeyTypeFactoryMethod() throws MalformedURLExceptio
547
548
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
548
549
rbd .setFactoryMethodName ("createInstance" );
549
550
550
- Map <String , String > input = new HashMap <String , String >();
551
+ Map <String , String > input = new HashMap <>();
551
552
input .put ("4" , "5" );
552
553
input .put ("6" , "7" );
553
554
rbd .getConstructorArgumentValues ().addGenericArgumentValue (input );
@@ -571,11 +572,11 @@ public void registerCustomEditors(PropertyEditorRegistry registry) {
571
572
RootBeanDefinition rbd = new RootBeanDefinition (GenericBean .class );
572
573
rbd .setFactoryMethodName ("createInstance" );
573
574
574
- Map <String , AbstractCollection <?>> input = new HashMap <String , AbstractCollection <?> >();
575
- HashSet <Integer > value1 = new HashSet <Integer >();
575
+ Map <String , AbstractCollection <?>> input = new HashMap <>();
576
+ HashSet <Integer > value1 = new HashSet <>();
576
577
value1 .add (new Integer (1 ));
577
578
input .put ("1" , value1 );
578
- ArrayList <Boolean > value2 = new ArrayList <Boolean >();
579
+ ArrayList <Boolean > value2 = new ArrayList <>();
579
580
value2 .add (Boolean .TRUE );
580
581
input .put ("2" , value2 );
581
582
rbd .getConstructorArgumentValues ().addGenericArgumentValue (Boolean .TRUE );
@@ -672,6 +673,8 @@ public void parameterizedStaticFactoryMethod() {
672
673
DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
673
674
bf .registerBeanDefinition ("mock" , rbd );
674
675
676
+ assertEquals (Runnable .class , bf .getType ("mock" ));
677
+ assertEquals (Runnable .class , bf .getType ("mock" ));
675
678
Map <String , Runnable > beans = bf .getBeansOfType (Runnable .class );
676
679
assertEquals (1 , beans .size ());
677
680
}
@@ -700,6 +703,10 @@ public void parameterizedInstanceFactoryMethod() {
700
703
rbd .getConstructorArgumentValues ().addGenericArgumentValue (Runnable .class );
701
704
bf .registerBeanDefinition ("mock" , rbd );
702
705
706
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
707
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
708
+ assertEquals (Runnable .class , bf .getType ("mock" ));
709
+ assertEquals (Runnable .class , bf .getType ("mock" ));
703
710
Map <String , Runnable > beans = bf .getBeansOfType (Runnable .class );
704
711
assertEquals (1 , beans .size ());
705
712
}
@@ -717,6 +724,10 @@ public void parameterizedInstanceFactoryMethodWithNonResolvedClassName() {
717
724
rbd .getConstructorArgumentValues ().addGenericArgumentValue (Runnable .class .getName ());
718
725
bf .registerBeanDefinition ("mock" , rbd );
719
726
727
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
728
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
729
+ assertEquals (Runnable .class , bf .getType ("mock" ));
730
+ assertEquals (Runnable .class , bf .getType ("mock" ));
720
731
Map <String , Runnable > beans = bf .getBeansOfType (Runnable .class );
721
732
assertEquals (1 , beans .size ());
722
733
}
@@ -732,6 +743,10 @@ public void parameterizedInstanceFactoryMethodWithWrappedClassName() {
732
743
rbd .getConstructorArgumentValues ().addGenericArgumentValue (new TypedStringValue (Runnable .class .getName ()));
733
744
bf .registerBeanDefinition ("mock" , rbd );
734
745
746
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
747
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
748
+ assertEquals (Runnable .class , bf .getType ("mock" ));
749
+ assertEquals (Runnable .class , bf .getType ("mock" ));
735
750
Map <String , Runnable > beans = bf .getBeansOfType (Runnable .class );
736
751
assertEquals (1 , beans .size ());
737
752
}
@@ -749,6 +764,10 @@ public void parameterizedInstanceFactoryMethodWithInvalidClassName() {
749
764
rbd .getConstructorArgumentValues ().addGenericArgumentValue ("x" );
750
765
bf .registerBeanDefinition ("mock" , rbd );
751
766
767
+ assertFalse (bf .isTypeMatch ("mock" , Runnable .class ));
768
+ assertFalse (bf .isTypeMatch ("mock" , Runnable .class ));
769
+ assertNull (bf .getType ("mock" ));
770
+ assertNull (bf .getType ("mock" ));
752
771
Map <String , Runnable > beans = bf .getBeansOfType (Runnable .class );
753
772
assertEquals (0 , beans .size ());
754
773
}
@@ -766,6 +785,32 @@ public void parameterizedInstanceFactoryMethodWithIndexedArgument() {
766
785
rbd .getConstructorArgumentValues ().addIndexedArgumentValue (0 , Runnable .class );
767
786
bf .registerBeanDefinition ("mock" , rbd );
768
787
788
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
789
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
790
+ assertEquals (Runnable .class , bf .getType ("mock" ));
791
+ assertEquals (Runnable .class , bf .getType ("mock" ));
792
+ Map <String , Runnable > beans = bf .getBeansOfType (Runnable .class );
793
+ assertEquals (1 , beans .size ());
794
+ }
795
+
796
+ @ Test // SPR-16720
797
+ public void parameterizedInstanceFactoryMethodWithTempClassLoader () {
798
+ DefaultListableBeanFactory bf = new DefaultListableBeanFactory ();
799
+ bf .setTempClassLoader (new OverridingClassLoader (getClass ().getClassLoader ()));
800
+
801
+ RootBeanDefinition rbd = new RootBeanDefinition (MocksControl .class );
802
+ bf .registerBeanDefinition ("mocksControl" , rbd );
803
+
804
+ rbd = new RootBeanDefinition ();
805
+ rbd .setFactoryBeanName ("mocksControl" );
806
+ rbd .setFactoryMethodName ("createMock" );
807
+ rbd .getConstructorArgumentValues ().addGenericArgumentValue (Runnable .class );
808
+ bf .registerBeanDefinition ("mock" , rbd );
809
+
810
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
811
+ assertTrue (bf .isTypeMatch ("mock" , Runnable .class ));
812
+ assertEquals (Runnable .class , bf .getType ("mock" ));
813
+ assertEquals (Runnable .class , bf .getType ("mock" ));
769
814
Map <String , Runnable > beans = bf .getBeansOfType (Runnable .class );
770
815
assertEquals (1 , beans .size ());
771
816
}
0 commit comments