Polishing
This commit is contained in:
parent
def10343ea
commit
4755467cca
|
|
@ -17,9 +17,11 @@
|
|||
package org.springframework.core.convert;
|
||||
|
||||
/**
|
||||
* Thrown when a suitable converter could not be found in a conversion service.
|
||||
* Exception to be thrown when a suitable converter could not be found
|
||||
* in a given conversion service.
|
||||
*
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
* @since 3.0
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
|
|
|
|||
|
|
@ -247,32 +247,7 @@ public class DefaultConversionServiceTests {
|
|||
@Test
|
||||
public void testStringToEnumSet() throws Exception {
|
||||
assertEquals(EnumSet.of(Foo.BAR), conversionService.convert("BAR", TypeDescriptor.valueOf(String.class),
|
||||
new TypeDescriptor(getClass().getField("enumSet"))));
|
||||
}
|
||||
|
||||
public EnumSet<Foo> enumSet;
|
||||
|
||||
|
||||
public enum Foo {
|
||||
BAR, BAZ
|
||||
}
|
||||
|
||||
public enum SubFoo {
|
||||
|
||||
BAR {
|
||||
@Override
|
||||
String s() {
|
||||
return "x";
|
||||
}
|
||||
},
|
||||
BAZ {
|
||||
@Override
|
||||
String s() {
|
||||
return "y";
|
||||
}
|
||||
};
|
||||
|
||||
abstract String s();
|
||||
new TypeDescriptor(getClass().getField("enumSet"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -344,8 +319,6 @@ public class DefaultConversionServiceTests {
|
|||
assertEquals("3", result.get(2));
|
||||
}
|
||||
|
||||
public List<Integer> genericList = new ArrayList<Integer>();
|
||||
|
||||
@Test
|
||||
public void convertArrayToCollectionGenericTypeConversion() throws Exception {
|
||||
@SuppressWarnings("unchecked")
|
||||
|
|
@ -356,8 +329,6 @@ public class DefaultConversionServiceTests {
|
|||
assertEquals(new Integer("3"), result.get(2));
|
||||
}
|
||||
|
||||
public Stream<Integer> genericStream;
|
||||
|
||||
@Test
|
||||
public void convertArrayToStream() throws Exception {
|
||||
String[] source = {"1", "3", "4"};
|
||||
|
|
@ -381,15 +352,6 @@ public class DefaultConversionServiceTests {
|
|||
assertEquals(Color.BLACK, colors.get(1));
|
||||
}
|
||||
|
||||
public class ColorConverter implements Converter<String, Color> {
|
||||
@Override
|
||||
public Color convert(String source) { if (!source.startsWith("#")) source = "#" + source; return Color.decode(source); }
|
||||
}
|
||||
|
||||
public void handlerMethod(List<Color> color) {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertArrayToCollectionImpl() {
|
||||
LinkedList<?> result = conversionService.convert(new String[] { "1", "2", "3" }, LinkedList.class);
|
||||
|
|
@ -400,7 +362,7 @@ public class DefaultConversionServiceTests {
|
|||
|
||||
@Test(expected = ConversionFailedException.class)
|
||||
public void convertArrayToAbstractCollection() {
|
||||
conversionService.convert(new String[] { "1", "2", "3" }, AbstractList.class);
|
||||
conversionService.convert(new String[]{"1", "2", "3"}, AbstractList.class);
|
||||
}
|
||||
|
||||
public static enum FooEnum {
|
||||
|
|
@ -599,7 +561,7 @@ public class DefaultConversionServiceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "cast", "unchecked" })
|
||||
@SuppressWarnings("unchecked")
|
||||
public void convertObjectToCollection() {
|
||||
List<String> result = (List<String>) conversionService.convert(3L, List.class);
|
||||
assertEquals(1, result.size());
|
||||
|
|
@ -635,7 +597,7 @@ public class DefaultConversionServiceTests {
|
|||
public void convertArrayToWrapperArray() {
|
||||
byte[] byteArray = new byte[] {1, 2, 3};
|
||||
Byte[] converted = conversionService.convert(byteArray, Byte[].class);
|
||||
assertThat(converted, equalTo(new Byte[] {1, 2, 3}));
|
||||
assertThat(converted, equalTo(new Byte[]{1, 2, 3}));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -693,7 +655,7 @@ public class DefaultConversionServiceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
public void convertCollectionToCollectionSpecialCaseSourceImpl() throws Exception {
|
||||
Map map = new LinkedHashMap();
|
||||
map.put("1", "1");
|
||||
|
|
@ -720,8 +682,6 @@ public class DefaultConversionServiceTests {
|
|||
assertEquals(new Integer(9), integers.get(1));
|
||||
}
|
||||
|
||||
public Map<Integer, FooEnum> genericMap = new HashMap<Integer, FooEnum>();
|
||||
|
||||
@Test
|
||||
public void convertMapToMap() throws Exception {
|
||||
Map<String, String> foo = new HashMap<String, String>();
|
||||
|
|
@ -735,7 +695,7 @@ public class DefaultConversionServiceTests {
|
|||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings({ "rawtypes" })
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void convertHashMapValuesToList() {
|
||||
Map<String, Integer> hashMap = new LinkedHashMap<String, Integer>();
|
||||
hashMap.put("1", 1);
|
||||
|
|
@ -877,7 +837,7 @@ public class DefaultConversionServiceTests {
|
|||
@Test
|
||||
public void convertStringToCharArray() throws Exception {
|
||||
char[] converted = conversionService.convert("a,b,c", char[].class);
|
||||
assertThat(converted, equalTo(new char[] {'a', 'b', 'c'}));
|
||||
assertThat(converted, equalTo(new char[]{'a', 'b', 'c'}));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -960,6 +920,54 @@ public class DefaultConversionServiceTests {
|
|||
}
|
||||
|
||||
|
||||
// test fields and helpers
|
||||
|
||||
public List<Integer> genericList = new ArrayList<Integer>();
|
||||
|
||||
public Stream<Integer> genericStream;
|
||||
|
||||
public Map<Integer, FooEnum> genericMap = new HashMap<Integer, FooEnum>();
|
||||
|
||||
public EnumSet<Foo> enumSet;
|
||||
|
||||
public Object assignableTarget;
|
||||
|
||||
|
||||
public void handlerMethod(List<Color> color) {
|
||||
}
|
||||
|
||||
|
||||
public enum Foo {
|
||||
BAR, BAZ
|
||||
}
|
||||
|
||||
|
||||
public enum SubFoo {
|
||||
|
||||
BAR {
|
||||
@Override
|
||||
String s() {
|
||||
return "x";
|
||||
}
|
||||
},
|
||||
BAZ {
|
||||
@Override
|
||||
String s() {
|
||||
return "y";
|
||||
}
|
||||
};
|
||||
|
||||
abstract String s();
|
||||
}
|
||||
|
||||
|
||||
public class ColorConverter implements Converter<String, Color> {
|
||||
|
||||
@Override
|
||||
public Color convert(String source) { if (!source.startsWith("#")) source = "#" + source; return Color.decode(source); }
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class CustomNumber extends Number {
|
||||
|
||||
|
|
@ -1020,9 +1028,6 @@ public class DefaultConversionServiceTests {
|
|||
}
|
||||
|
||||
|
||||
public Object assignableTarget;
|
||||
|
||||
|
||||
private static class SSN {
|
||||
|
||||
static int constructorCount = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue