1
1
/*
2
- * Copyright 2002-2016 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 ;
@@ -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