completed generic converter implementation

This commit is contained in:
Keith Donald
2009-09-23 18:25:04 +00:00
parent ce800fb45a
commit 7a6dafd5ad
21 changed files with 595 additions and 501 deletions

View File

@@ -453,6 +453,48 @@ public class GenericConversionServiceTests {
assertEquals(FooEnum.BAZ, result.get(2));
}
@Test
public void convertMapToString() {
Map<String, String> foo = new LinkedHashMap<String, String>();
foo.put("1", "BAR");
foo.put("2", "BAZ");
String result = conversionService.convert(foo, String.class);
assertEquals("1=BAR 2=BAZ", result);
}
@Test
public void convertMapToStringWithConversion() throws Exception {
Map<Integer, FooEnum> foo = new LinkedHashMap<Integer, FooEnum>();
foo.put(1, FooEnum.BAR);
foo.put(2, FooEnum.BAZ);
conversionService.addConverter(new ObjectToStringConverter());
String result = (String) conversionService.convert(foo, new TypeDescriptor(getClass().getField("genericMap")),
TypeDescriptor.valueOf(String.class));
assertEquals("1=BAR 2=BAZ", result);
}
@Test
public void convertMapToObject() {
Map<Long, Long> foo = new LinkedHashMap<Long, Long>();
foo.put(1L, 1L);
foo.put(2L, 2L);
Long result = conversionService.convert(foo, Long.class);
assertEquals(new Long(1), result);
}
public Map<Long, Long> genericMap2 = new HashMap<Long, Long>();
@Test
public void convertMapToObjectWithConversion() throws Exception {
Map<Long, Long> foo = new LinkedHashMap<Long, Long>();
foo.put(1L, 1L);
foo.put(2L, 2L);
conversionService.addConverterFactory(new NumberToNumberConverterFactory());
Integer result = (Integer) conversionService.convert(foo,
new TypeDescriptor(getClass().getField("genericMap2")), TypeDescriptor.valueOf(Integer.class));
assertEquals(new Integer(1), result);
}
@Test
public void genericConverterDelegatingBackToConversionServiceConverterNotFound() {
try {