Polishing
This commit is contained in:
@@ -200,7 +200,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
}
|
||||
|
||||
|
||||
// subclassing hooks
|
||||
// Protected template methods
|
||||
|
||||
/**
|
||||
* Template method to convert a null source.
|
||||
@@ -548,7 +548,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
Class<?> candidate = hierarchy.get(i);
|
||||
candidate = (array ? candidate.getComponentType() : ClassUtils.resolvePrimitiveIfNecessary(candidate));
|
||||
Class<?> superclass = candidate.getSuperclass();
|
||||
if (candidate.getSuperclass() != null && superclass != Object.class) {
|
||||
if (superclass != null && superclass != Object.class) {
|
||||
addToClassHierarchy(i + 1, candidate.getSuperclass(), array, hierarchy, visited);
|
||||
}
|
||||
for (Class<?> implementedInterface : candidate.getInterfaces()) {
|
||||
@@ -563,6 +563,7 @@ public class GenericConversionService implements ConfigurableConversionService {
|
||||
|
||||
private void addToClassHierarchy(int index, Class<?> type, boolean asArray,
|
||||
List<Class<?>> hierarchy, Set<Class<?>> visited) {
|
||||
|
||||
if (asArray) {
|
||||
type = Array.newInstance(type, 0).getClass();
|
||||
}
|
||||
|
||||
@@ -194,7 +194,6 @@ public class SocketUtils {
|
||||
private static enum SocketType {
|
||||
|
||||
TCP {
|
||||
|
||||
@Override
|
||||
protected boolean isPortAvailable(int port) {
|
||||
try {
|
||||
@@ -209,7 +208,6 @@ public class SocketUtils {
|
||||
},
|
||||
|
||||
UDP {
|
||||
|
||||
@Override
|
||||
protected boolean isPortAvailable(int port) {
|
||||
try {
|
||||
|
||||
@@ -57,11 +57,13 @@ import static org.junit.Assert.*;
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
* @author Phillip Webb
|
||||
* @author David Haraburda
|
||||
*/
|
||||
public class GenericConversionServiceTests {
|
||||
|
||||
private GenericConversionService conversionService = new GenericConversionService();
|
||||
|
||||
|
||||
@Test
|
||||
public void canConvert() {
|
||||
assertFalse(conversionService.canConvert(String.class, Integer.class));
|
||||
@@ -749,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
|
||||
@@ -850,6 +859,7 @@ public class GenericConversionServiceTests {
|
||||
@ExampleAnnotation
|
||||
public String annotatedString;
|
||||
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public static @interface ExampleAnnotation {
|
||||
}
|
||||
@@ -892,8 +902,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;
|
||||
}
|
||||
|
||||
@@ -936,6 +945,7 @@ public class GenericConversionServiceTests {
|
||||
String getCode();
|
||||
}
|
||||
|
||||
|
||||
public static enum MyEnum implements MyEnumInterface {
|
||||
|
||||
A {
|
||||
@@ -947,6 +957,17 @@ public class GenericConversionServiceTests {
|
||||
}
|
||||
|
||||
|
||||
public enum EnumWithSubclass {
|
||||
|
||||
FIRST {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "1st";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class MyStringToRawCollectionConverter implements Converter<String, Collection> {
|
||||
|
||||
@Override
|
||||
@@ -955,6 +976,7 @@ public class GenericConversionServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class MyStringToGenericCollectionConverter implements Converter<String, Collection<?>> {
|
||||
|
||||
@Override
|
||||
@@ -963,6 +985,7 @@ public class GenericConversionServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class MyEnumInterfaceToStringConverter<T extends MyEnumInterface> implements Converter<T, String> {
|
||||
|
||||
@Override
|
||||
@@ -971,6 +994,7 @@ public class GenericConversionServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class MyStringToStringCollectionConverter implements Converter<String, Collection<String>> {
|
||||
|
||||
@Override
|
||||
@@ -979,6 +1003,7 @@ public class GenericConversionServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static class MyStringToIntegerCollectionConverter implements Converter<String, Collection<Integer>> {
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user