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

This commit is contained in:
Keith Donald
2011-06-07 20:00:28 +00:00
parent df460f4486
commit 1e39b0bbbc
22 changed files with 239 additions and 71 deletions

View File

@@ -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 {

View File

@@ -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) {
}
}

View File

@@ -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));