21
21
import java .beans .IntrospectionException ;
22
22
import java .beans .Introspector ;
23
23
import java .beans .PropertyDescriptor ;
24
-
25
- import java .lang .reflect .Method ;
26
24
import java .math .BigDecimal ;
27
25
28
26
import org .junit .Test ;
29
27
30
28
import org .springframework .core .JdkVersion ;
31
29
import org .springframework .tests .sample .beans .TestBean ;
32
- import org .springframework .util .ClassUtils ;
33
-
34
-
35
- import static org .hamcrest .Matchers .greaterThan ;
36
- import static org .hamcrest .Matchers .lessThan ;
37
-
38
30
39
31
import static org .hamcrest .CoreMatchers .equalTo ;
40
32
import static org .hamcrest .CoreMatchers .is ;
41
-
33
+ import static org . hamcrest . Matchers .*;
42
34
import static org .junit .Assert .*;
43
35
44
36
/**
45
- * Unit tests for {@link ExtendedBeanInfo}.
46
- *
47
37
* @author Chris Beams
48
38
* @since 3.1
49
39
*/
@@ -208,10 +198,6 @@ public Integer getProperty1() {
208
198
}
209
199
}
210
200
211
- interface Spr9453 <T > {
212
- T getProp ();
213
- }
214
-
215
201
@ Test
216
202
public void cornerSpr9453 () throws IntrospectionException {
217
203
final class Bean implements Spr9453 <Class <?>> {
@@ -597,7 +583,6 @@ public void cornerSpr10111() throws Exception {
597
583
new ExtendedBeanInfo (Introspector .getBeanInfo (BigDecimal .class ));
598
584
}
599
585
600
-
601
586
@ Test
602
587
public void subclassWriteMethodWithCovariantReturnType () throws IntrospectionException {
603
588
@ SuppressWarnings ("unused" ) class B {
@@ -796,6 +781,7 @@ public void propertyDescriptorOrderIsEqual() throws IntrospectionException {
796
781
@ Test
797
782
public void propertyDescriptorComparator () throws IntrospectionException {
798
783
PropertyDescriptorComparator c = new PropertyDescriptorComparator ();
784
+
799
785
assertThat (c .compare (new PropertyDescriptor ("a" , null , null ), new PropertyDescriptor ("a" , null , null )), equalTo (0 ));
800
786
assertThat (c .compare (new PropertyDescriptor ("abc" , null , null ), new PropertyDescriptor ("abc" , null , null )), equalTo (0 ));
801
787
assertThat (c .compare (new PropertyDescriptor ("a" , null , null ), new PropertyDescriptor ("b" , null , null )), lessThan (0 ));
@@ -867,33 +853,6 @@ public void reproSpr8806() throws IntrospectionException {
867
853
new ExtendedBeanInfo (Introspector .getBeanInfo (LawLibrary .class ));
868
854
}
869
855
870
- interface Book { }
871
-
872
- interface TextBook extends Book { }
873
-
874
- interface LawBook extends TextBook { }
875
-
876
- interface BookOperations {
877
- Book getBook ();
878
- void setBook (Book book );
879
- }
880
-
881
- interface TextBookOperations extends BookOperations {
882
- @ Override
883
- TextBook getBook ();
884
- }
885
-
886
- abstract class Library {
887
- public Book getBook () { return null ; }
888
- public void setBook (Book book ) { }
889
- }
890
-
891
- class LawLibrary extends Library implements TextBookOperations {
892
- @ Override
893
- public LawBook getBook () { return null ; }
894
- }
895
-
896
-
897
856
@ Test
898
857
public void cornerSpr8949 () throws IntrospectionException {
899
858
class A {
@@ -912,23 +871,10 @@ public boolean isTargetMethod() {
912
871
913
872
BeanInfo bi = Introspector .getBeanInfo (B .class );
914
873
915
- /* first, demonstrate the 'problem':
916
- * java.beans.Introspector returns the "wrong" declaring class for overridden read
917
- * methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding
918
- * method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)}
919
- * helps out here, and is now put into use in ExtendedBeanInfo as well
920
- */
921
- for (PropertyDescriptor pd : bi .getPropertyDescriptors ()) {
922
- if ("targetMethod" .equals (pd .getName ())) {
923
- Method readMethod = pd .getReadMethod ();
924
- assertTrue (readMethod .getDeclaringClass ().equals (A .class )); // we expected B!
925
-
926
- Method msReadMethod = ClassUtils .getMostSpecificMethod (readMethod , B .class );
927
- assertTrue (msReadMethod .getDeclaringClass ().equals (B .class )); // and now we get it.
928
- }
929
- }
930
-
931
- // and now demonstrate that we've indeed fixed the problem
874
+ // java.beans.Introspector returns the "wrong" declaring class for overridden read
875
+ // methods, which in turn violates expectations in {@link ExtendedBeanInfo} regarding
876
+ // method equality. Spring's {@link ClassUtils#getMostSpecificMethod(Method, Class)}
877
+ // helps out here, and is now put into use in ExtendedBeanInfo as well.
932
878
BeanInfo ebi = new ExtendedBeanInfo (bi );
933
879
934
880
assertThat (hasReadMethodForProperty (bi , "targetMethod" ), is (true ));
@@ -980,8 +926,56 @@ public void shouldSupportStaticWriteMethod() throws IntrospectionException {
980
926
}
981
927
}
982
928
929
+
930
+ interface Spr9453 <T > {
931
+
932
+ T getProp ();
933
+ }
934
+
935
+ interface Book {
936
+ }
937
+
938
+ interface TextBook extends Book {
939
+ }
940
+
941
+ interface LawBook extends TextBook {
942
+ }
943
+
944
+ interface BookOperations {
945
+
946
+ Book getBook ();
947
+
948
+ void setBook (Book book );
949
+ }
950
+
951
+ interface TextBookOperations extends BookOperations {
952
+
953
+ @ Override
954
+ TextBook getBook ();
955
+ }
956
+
957
+ abstract class Library {
958
+
959
+ public Book getBook () {
960
+ return null ;
961
+ }
962
+
963
+ public void setBook (Book book ) {
964
+ }
965
+ }
966
+
967
+ class LawLibrary extends Library implements TextBookOperations {
968
+
969
+ @ Override
970
+ public LawBook getBook () {
971
+ return null ;
972
+ }
973
+ }
974
+
983
975
static class WithStaticWriteMethod {
976
+
984
977
public static void setProp1 (String prop1 ) {
985
978
}
986
979
}
980
+
987
981
}
0 commit comments