Polishing
Issue: SPR-11369
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@@ -682,7 +683,7 @@ public class GenericConversionServiceTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotSuportNullConvertibleTypesFromNonConditionalGenericConverter() {
|
||||
public void shouldNotSupportNullConvertibleTypesFromNonConditionalGenericConverter() {
|
||||
GenericConversionService conversionService = new GenericConversionService();
|
||||
GenericConverter converter = new GenericConverter() {
|
||||
@Override
|
||||
@@ -766,6 +767,41 @@ public class GenericConversionServiceTests {
|
||||
conversionService.convert(source, sourceType, targetType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void multipleCollectionTypesFromSameSourceType() throws Exception {
|
||||
conversionService.addConverter(new MyStringToStringCollectionConverter());
|
||||
conversionService.addConverter(new MyStringToIntegerCollectionConverter());
|
||||
assertEquals(Collections.singleton(4), // should be "testX" from MyStringToStringCollectionConverter, ideally
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("stringCollection"))));
|
||||
assertEquals(Collections.singleton(4),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("integerCollection"))));
|
||||
assertEquals(Collections.singleton(4),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("rawCollection"))));
|
||||
assertEquals(Collections.singleton(4),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("genericCollection"))));
|
||||
assertEquals(Collections.singleton(4),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("rawCollection"))));
|
||||
assertEquals(Collections.singleton(4), // should be "testX" from MyStringToStringCollectionConverter, ideally
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("stringCollection"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void adaptedCollectionTypesFromSameSourceType() throws Exception {
|
||||
conversionService.addConverter(new MyStringToStringCollectionConverter());
|
||||
assertEquals(Collections.singleton("testX"),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("stringCollection"))));
|
||||
assertEquals(Collections.singleton("testX"),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("genericCollection"))));
|
||||
assertEquals(Collections.singleton("testX"),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("rawCollection"))));
|
||||
assertEquals(Collections.singleton("testX"),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("genericCollection"))));
|
||||
assertEquals(Collections.singleton("testX"),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("stringCollection"))));
|
||||
assertEquals(Collections.singleton("testX"),
|
||||
conversionService.convert("test", TypeDescriptor.valueOf(String.class), new TypeDescriptor(getClass().getField("rawCollection"))));
|
||||
}
|
||||
|
||||
|
||||
@ExampleAnnotation
|
||||
public String annotatedString;
|
||||
@@ -872,4 +908,28 @@ public class GenericConversionServiceTests {
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyStringToStringCollectionConverter implements Converter<String, Collection<String>> {
|
||||
|
||||
@Override
|
||||
public Collection<String> convert(String source) {
|
||||
return Collections.singleton(source + "X");
|
||||
}
|
||||
}
|
||||
|
||||
public static class MyStringToIntegerCollectionConverter implements Converter<String, Collection<Integer>> {
|
||||
|
||||
@Override
|
||||
public Collection<Integer> convert(String source) {
|
||||
return Collections.singleton(source.length());
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<String> stringCollection;
|
||||
|
||||
public Collection<Integer> integerCollection;
|
||||
|
||||
public Collection rawCollection;
|
||||
|
||||
public Collection<?> genericCollection;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user