found hotspot; added ConverisonServiceFactoryBean
This commit is contained in:
@@ -25,26 +25,14 @@ import org.springframework.core.convert.ConversionService;
|
||||
*/
|
||||
public final class ConversionServiceFactory {
|
||||
|
||||
private static ConversionService DEFAULT_INSTANCE;
|
||||
|
||||
private ConversionServiceFactory() {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the shared default ConversionService.
|
||||
*/
|
||||
public static synchronized ConversionService getDefault() {
|
||||
if (DEFAULT_INSTANCE == null) {
|
||||
DEFAULT_INSTANCE = createDefault();
|
||||
}
|
||||
return DEFAULT_INSTANCE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new default ConversionService prototype that can be safely modified.
|
||||
*/
|
||||
public static ConversionService createDefault() {
|
||||
public static ConversionService createDefaultConversionService() {
|
||||
GenericConversionService conversionService = new GenericConversionService();
|
||||
conversionService.addGenericConverter(new ArrayToArrayConverter(conversionService));
|
||||
conversionService.addGenericConverter(new ArrayToCollectionConverter(conversionService));
|
||||
|
||||
@@ -48,25 +48,7 @@ import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
public class DefaultConversionTests {
|
||||
|
||||
private ConversionService conversionService = ConversionServiceFactory.getDefault();
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testUnmodifiableListConversion() {
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
stringList.add("foo");
|
||||
stringList.add("bar");
|
||||
|
||||
List<String> frozenList = Collections.unmodifiableList(stringList);
|
||||
|
||||
List<String> converted = conversionService.convert(frozenList, List.class);
|
||||
|
||||
// The converted list should contain all the elements in the original list
|
||||
Assert.assertEquals(frozenList, converted);
|
||||
// Looks like it was supposed to be a copy (but CollectionToCollectionConverter
|
||||
// doesn't work that way right now). Commented out (DS).
|
||||
// Assert.assertNotSame(frozenList, converted);
|
||||
}
|
||||
private ConversionService conversionService = ConversionServiceFactory.createDefaultConversionService();
|
||||
|
||||
@Test
|
||||
public void testStringToCharacter() {
|
||||
@@ -740,4 +722,22 @@ public class DefaultConversionTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testUnmodifiableListConversion() {
|
||||
List<String> stringList = new ArrayList<String>();
|
||||
stringList.add("foo");
|
||||
stringList.add("bar");
|
||||
|
||||
List<String> frozenList = Collections.unmodifiableList(stringList);
|
||||
|
||||
List<String> converted = conversionService.convert(frozenList, List.class);
|
||||
|
||||
// The converted list should contain all the elements in the original list
|
||||
Assert.assertEquals(frozenList, converted);
|
||||
// TODO Looks like it was supposed to be a copy (but CollectionToCollectionConverter
|
||||
// doesn't work that way right now). Commented out (DS).
|
||||
// Assert.assertNotSame(frozenList, converted);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user