@ -63,6 +63,7 @@ public class GenericConversionServiceTests {
@@ -63,6 +63,7 @@ public class GenericConversionServiceTests {
private GenericConversionService conversionService = new GenericConversionService ( ) ;
@Test
public void canConvert ( ) {
assertFalse ( conversionService . canConvert ( String . class , Integer . class ) ) ;
@ -750,6 +751,13 @@ public class GenericConversionServiceTests {
@@ -750,6 +751,13 @@ public class GenericConversionServiceTests {
assertEquals ( "A" , result ) ;
}
@Test
public void testSubclassOfEnumToString ( ) throws Exception {
conversionService . addConverter ( new EnumToStringConverter ( conversionService ) ) ;
String result = conversionService . convert ( EnumWithSubclass . FIRST , String . class ) ;
assertEquals ( "FIRST" , result ) ;
}
@Test
public void testEnumWithInterfaceToStringConversion ( ) {
// SPR-9692
@ -865,6 +873,7 @@ public class GenericConversionServiceTests {
@@ -865,6 +873,7 @@ public class GenericConversionServiceTests {
@ExampleAnnotation
public String annotatedString ;
@Retention ( RetentionPolicy . RUNTIME )
public static @interface ExampleAnnotation {
}
@ -907,8 +916,7 @@ public class GenericConversionServiceTests {
@@ -907,8 +916,7 @@ public class GenericConversionServiceTests {
}
@Override
public Object convert ( Object source , TypeDescriptor sourceType ,
TypeDescriptor targetType ) {
public Object convert ( Object source , TypeDescriptor sourceType , TypeDescriptor targetType ) {
return null ;
}
@ -945,14 +953,19 @@ public class GenericConversionServiceTests {
@@ -945,14 +953,19 @@ public class GenericConversionServiceTests {
}
}
interface MyEnumBaseInterface {
String getBaseCode ( ) ;
}
interface MyEnumInterface extends MyEnumBaseInterface {
String getCode ( ) ;
}
public static enum MyEnum implements MyEnumInterface {
A ( "1" ) ,
@ -977,6 +990,17 @@ public class GenericConversionServiceTests {
@@ -977,6 +990,17 @@ public class GenericConversionServiceTests {
}
public enum EnumWithSubclass {
FIRST {
@Override
public String toString ( ) {
return "1st" ;
}
}
}
public static class MyStringToRawCollectionConverter implements Converter < String , Collection > {
@Override
@ -985,6 +1009,7 @@ public class GenericConversionServiceTests {
@@ -985,6 +1009,7 @@ public class GenericConversionServiceTests {
}
}
public static class MyStringToGenericCollectionConverter implements Converter < String , Collection < ? > > {
@Override
@ -993,6 +1018,7 @@ public class GenericConversionServiceTests {
@@ -993,6 +1018,7 @@ public class GenericConversionServiceTests {
}
}
private static class MyEnumInterfaceToStringConverter < T extends MyEnumInterface > implements Converter < T , String > {
@Override
@ -1001,6 +1027,7 @@ public class GenericConversionServiceTests {
@@ -1001,6 +1027,7 @@ public class GenericConversionServiceTests {
}
}
private static class StringToMyEnumInterfaceConverterFactory implements ConverterFactory < String , MyEnumInterface > {
@SuppressWarnings ( "unchecked" )
@ -1024,9 +1051,9 @@ public class GenericConversionServiceTests {
@@ -1024,9 +1051,9 @@ public class GenericConversionServiceTests {
return null ;
}
}
}
private static class StringToMyEnumBaseInterfaceConverterFactory implements ConverterFactory < String , MyEnumBaseInterface > {
@SuppressWarnings ( "unchecked" )
@ -1050,7 +1077,6 @@ public class GenericConversionServiceTests {
@@ -1050,7 +1077,6 @@ public class GenericConversionServiceTests {
return null ;
}
}
}
@ -1062,6 +1088,7 @@ public class GenericConversionServiceTests {
@@ -1062,6 +1088,7 @@ public class GenericConversionServiceTests {
}
}
public static class MyStringToIntegerCollectionConverter implements Converter < String , Collection < Integer > > {
@Override