implemented collection/map converter conditional matching checks; updated SpEL to reflect this behavior

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@4483 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Keith Donald
2011-06-07 20:00:28 +00:00
parent cfd8d7dac4
commit f40c101d6d
22 changed files with 239 additions and 71 deletions
@@ -175,16 +175,16 @@ public class CollectionToCollectionConverterTests {
assertEquals(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
}
@Test
public void allNullsNotConvertible() throws Exception {
@Test(expected=ConverterNotFoundException.class)
public void elementTypesNotConvertible() throws Exception {
List<Resource> resources = new ArrayList<Resource>();
resources.add(null);
resources.add(null);
TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("allNullsNotConvertible"));
TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("strings"));
assertEquals(resources, conversionService.convert(resources, sourceType, new TypeDescriptor(getClass().getField("resources"))));
}
public List<String> allNullsNotConvertible;
public List<String> strings;
@Test(expected=ConversionFailedException.class)
public void nothingInCommon() throws Exception {
@@ -225,11 +225,11 @@ public class GenericConversionServiceTests {
@Test
public void genericConverterDelegatingBackToConversionServiceConverterNotFound() {
conversionService.addConverter(new ObjectToArrayConverter(conversionService));
assertTrue(conversionService.canConvert(String.class, Integer[].class));
assertFalse(conversionService.canConvert(String.class, Integer[].class));
try {
conversionService.convert("3,4,5", Integer[].class);
} catch (ConversionFailedException e) {
assertTrue(e.getCause() instanceof ConverterNotFoundException);
fail("should have failed");
} catch (ConverterNotFoundException e) {
}
}
@@ -3,6 +3,7 @@ package org.springframework.core.convert.support;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.util.Arrays;
import java.util.HashMap;
@@ -114,12 +115,13 @@ public class MapToMapConverterTests {
map.put("2", Arrays.asList("37", "23"));
TypeDescriptor sourceType = new TypeDescriptor(getClass().getField("sourceCollectionMapTarget"));
TypeDescriptor targetType = new TypeDescriptor(getClass().getField("collectionMapTarget"));
assertTrue(conversionService.canConvert(sourceType, targetType));
assertFalse(conversionService.canConvert(sourceType, targetType));
try {
conversionService.convert(map, sourceType, targetType);
} catch (ConversionFailedException e) {
assertTrue(e.getCause() instanceof ConverterNotFoundException);
}
fail("Should have failed");
} catch (ConverterNotFoundException e) {
}
conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
conversionService.addConverterFactory(new StringToNumberConverterFactory());
assertTrue(conversionService.canConvert(sourceType, targetType));