canConvert checks Collection/Map element types as well (SPR-6564)
This commit is contained in:
@@ -1,6 +1,23 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
@@ -14,6 +31,13 @@ public class ResourceTestBean {
|
||||
|
||||
private InputStream inputStream;
|
||||
|
||||
private Resource[] resourceArray;
|
||||
|
||||
private Map<String, Resource> resourceMap;
|
||||
|
||||
private Map<String, Resource[]> resourceArrayMap;
|
||||
|
||||
|
||||
public ResourceTestBean() {
|
||||
}
|
||||
|
||||
@@ -22,6 +46,7 @@ public class ResourceTestBean {
|
||||
this.inputStream = inputStream;
|
||||
}
|
||||
|
||||
|
||||
public void setResource(Resource resource) {
|
||||
this.resource = resource;
|
||||
}
|
||||
@@ -38,4 +63,28 @@ public class ResourceTestBean {
|
||||
return inputStream;
|
||||
}
|
||||
|
||||
public Resource[] getResourceArray() {
|
||||
return resourceArray;
|
||||
}
|
||||
|
||||
public void setResourceArray(Resource[] resourceArray) {
|
||||
this.resourceArray = resourceArray;
|
||||
}
|
||||
|
||||
public Map<String, Resource> getResourceMap() {
|
||||
return resourceMap;
|
||||
}
|
||||
|
||||
public void setResourceMap(Map<String, Resource> resourceMap) {
|
||||
this.resourceMap = resourceMap;
|
||||
}
|
||||
|
||||
public Map<String, Resource[]> getResourceArrayMap() {
|
||||
return resourceArrayMap;
|
||||
}
|
||||
|
||||
public void setResourceArrayMap(Map<String, Resource[]> resourceArrayMap) {
|
||||
this.resourceArrayMap = resourceArrayMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,18 +1,42 @@
|
||||
/*
|
||||
* Copyright 2002-2010 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.context.support;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.ResourceTestBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.core.convert.converter.ConverterFactory;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
|
||||
/**
|
||||
* @author Keith Donald
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class ConversionServiceFactoryBeanTests {
|
||||
|
||||
@Test
|
||||
@@ -67,15 +91,27 @@ public class ConversionServiceFactoryBeanTests {
|
||||
factory.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void conversionServiceInApplicationContext() {
|
||||
ApplicationContext ctx = new ClassPathXmlApplicationContext("conversionService.xml", getClass());
|
||||
ResourceTestBean tb = ctx.getBean("resourceTestBean", ResourceTestBean.class);
|
||||
assertTrue(tb.getResource() instanceof ClassPathResource);
|
||||
assertTrue(tb.getResourceArray().length > 1);
|
||||
assertTrue(tb.getResourceArray()[0] instanceof FileSystemResource);
|
||||
assertTrue(tb.getResourceMap().size() == 1);
|
||||
assertTrue(tb.getResourceMap().get("key1") instanceof ClassPathResource);
|
||||
assertTrue(tb.getResourceArrayMap().size() == 1);
|
||||
assertTrue(tb.getResourceArrayMap().get("key1").length > 1);
|
||||
assertTrue(tb.getResourceArrayMap().get("key1")[0] instanceof FileSystemResource);
|
||||
}
|
||||
|
||||
|
||||
public static class Foo {
|
||||
|
||||
}
|
||||
|
||||
public static class Bar {
|
||||
|
||||
}
|
||||
|
||||
public static class Baz {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring-beans-2.0.dtd">
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="customEditorConfigurer" class="org.springframework.beans.factory.config.CustomEditorConfigurer">
|
||||
<property name="customEditors">
|
||||
<map key-type="java.lang.String" value-type="java.lang.Class">
|
||||
<entry key="org.springframework.core.io.Resource[]" value="org.springframework.core.io.support.ResourceArrayPropertyEditor"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="conversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"/>
|
||||
|
||||
<bean id="resourceTestBean" class="org.springframework.beans.ResourceTestBean">
|
||||
<property name="resource" value="org/springframework/context/support/conversionService.xml"/>
|
||||
<property name="resourceArray" value="org/springframework/context/support/*.xml"/>
|
||||
<property name="resourceMap">
|
||||
<map>
|
||||
<entry key="key1" value="org/springframework/context/support/conversionService.xml"/>
|
||||
</map>
|
||||
</property>
|
||||
<property name="resourceArrayMap">
|
||||
<map>
|
||||
<entry key="key1" value="org/springframework/context/support/*.xml"/>
|
||||
</map>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user