Convert comma-separated string into list of classes analogous to existing support for class array

Issue: SPR-14415
This commit is contained in:
Juergen Hoeller
2016-06-30 14:02:51 +02:00
parent 89396ff01f
commit c4c941c43f
5 changed files with 60 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 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.
@@ -29,6 +29,7 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.BeanCreationException;
@@ -52,14 +53,16 @@ import static org.junit.Assert.*;
*/
public class XmlBeanCollectionTests {
private final DefaultListableBeanFactory beanFactory;
private final DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
public XmlBeanCollectionTests() {
this.beanFactory = new DefaultListableBeanFactory();
@Before
public void loadBeans() {
new XmlBeanDefinitionReader(this.beanFactory).loadBeanDefinitions(
new ClassPathResource("collections.xml", getClass()));
}
@Test
public void testCollectionFactoryDefaults() throws Exception {
ListFactoryBean listFactory = new ListFactoryBean();
@@ -327,6 +330,15 @@ public class XmlBeanCollectionTests {
assertTrue(hasMap.getObjectArray()[1].equals(this.beanFactory.getBean("jenny")));
}
@Test
public void testIntegerArray() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("integerArray");
assertTrue(hasMap.getIntegerArray().length == 3);
assertTrue(hasMap.getIntegerArray()[0].intValue() == 0);
assertTrue(hasMap.getIntegerArray()[1].intValue() == 1);
assertTrue(hasMap.getIntegerArray()[2].intValue() == 2);
}
@Test
public void testClassArray() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("classArray");
@@ -336,12 +348,11 @@ public class XmlBeanCollectionTests {
}
@Test
public void testIntegerArray() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("integerArray");
assertTrue(hasMap.getIntegerArray().length == 3);
assertTrue(hasMap.getIntegerArray()[0].intValue() == 0);
assertTrue(hasMap.getIntegerArray()[1].intValue() == 1);
assertTrue(hasMap.getIntegerArray()[2].intValue() == 2);
public void testClassList() throws Exception {
HasMap hasMap = (HasMap) this.beanFactory.getBean("classList");
assertTrue(hasMap.getClassList().size()== 2);
assertTrue(hasMap.getClassList().get(0).equals(String.class));
assertTrue(hasMap.getClassList().get(1).equals(Exception.class));
}
@Test
@@ -447,4 +458,5 @@ public class XmlBeanCollectionTests {
return obj;
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2016 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.
@@ -17,6 +17,7 @@
package org.springframework.tests.sample.beans;
import java.util.IdentityHashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
@@ -38,9 +39,11 @@ public class HasMap {
private Object[] objectArray;
private Integer[] intArray;
private Class<?>[] classArray;
private Integer[] intArray;
private List<Class<?>> classList;
private IdentityHashMap identityMap;
@@ -81,6 +84,14 @@ public class HasMap {
this.objectArray = objectArray;
}
public Integer[] getIntegerArray() {
return intArray;
}
public void setIntegerArray(Integer[] is) {
intArray = is;
}
public Class<?>[] getClassArray() {
return classArray;
}
@@ -89,12 +100,12 @@ public class HasMap {
this.classArray = classArray;
}
public Integer[] getIntegerArray() {
return intArray;
public List<Class<?>> getClassList() {
return classList;
}
public void setIntegerArray(Integer[] is) {
intArray = is;
public void setClassList(List<Class<?>> classList) {
this.classList = classList;
}
public IdentityHashMap getIdentityMap() {