testing the exception message when conversion of a generic collection element fails
This commit is contained in:
parent
171b855d10
commit
5fed34bdb4
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2008 the original author or authors.
|
* Copyright 2002-2009 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package org.springframework.beans.factory.support;
|
package org.springframework.beans.factory.support;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
|
||||||
|
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -30,18 +28,21 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import test.beans.GenericBean;
|
||||||
|
import test.beans.GenericIntegerBean;
|
||||||
|
import test.beans.GenericSetOfIntegerBean;
|
||||||
|
import test.beans.TestBean;
|
||||||
|
|
||||||
import org.springframework.beans.PropertyEditorRegistrar;
|
import org.springframework.beans.PropertyEditorRegistrar;
|
||||||
import org.springframework.beans.PropertyEditorRegistry;
|
import org.springframework.beans.PropertyEditorRegistry;
|
||||||
|
import org.springframework.beans.factory.BeanCreationException;
|
||||||
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
import org.springframework.beans.factory.xml.XmlBeanFactory;
|
||||||
import org.springframework.beans.propertyeditors.CustomNumberEditor;
|
import org.springframework.beans.propertyeditors.CustomNumberEditor;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
import org.springframework.core.io.UrlResource;
|
import org.springframework.core.io.UrlResource;
|
||||||
|
|
||||||
import test.beans.GenericBean;
|
|
||||||
import test.beans.GenericIntegerBean;
|
|
||||||
import test.beans.GenericSetOfIntegerBean;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Juergen Hoeller
|
* @author Juergen Hoeller
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
@ -97,6 +98,26 @@ public class BeanFactoryGenericsTests {
|
||||||
assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
|
assertEquals(new UrlResource("http://localhost:9090"), gb.getResourceList().get(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGenericListPropertyWithInvalidElementType() {
|
||||||
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
|
RootBeanDefinition rbd = new RootBeanDefinition(GenericIntegerBean.class);
|
||||||
|
|
||||||
|
List input = new ArrayList();
|
||||||
|
input.add(1);
|
||||||
|
rbd.getPropertyValues().addPropertyValue("testBeanList", input);
|
||||||
|
|
||||||
|
bf.registerBeanDefinition("genericBean", rbd);
|
||||||
|
try {
|
||||||
|
bf.getBean("genericBean");
|
||||||
|
fail("Should have thrown BeanCreationException");
|
||||||
|
}
|
||||||
|
catch (BeanCreationException ex) {
|
||||||
|
assertTrue(ex.getMessage().contains("genericBean") && ex.getMessage().contains("testBeanList[0]"));
|
||||||
|
assertTrue(ex.getMessage().contains(TestBean.class.getName()) && ex.getMessage().contains("Integer"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenericListPropertyWithOptionalAutowiring() throws MalformedURLException {
|
public void testGenericListPropertyWithOptionalAutowiring() throws MalformedURLException {
|
||||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||||
|
|
|
@ -38,6 +38,8 @@ public class GenericBean<T> {
|
||||||
|
|
||||||
private List<Resource> resourceList;
|
private List<Resource> resourceList;
|
||||||
|
|
||||||
|
private List<TestBean> testBeanList;
|
||||||
|
|
||||||
private List<List<Integer>> listOfLists;
|
private List<List<Integer>> listOfLists;
|
||||||
|
|
||||||
private ArrayList<String[]> listOfArrays;
|
private ArrayList<String[]> listOfArrays;
|
||||||
|
@ -123,6 +125,14 @@ public class GenericBean<T> {
|
||||||
this.resourceList = resourceList;
|
this.resourceList = resourceList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<TestBean> getTestBeanList() {
|
||||||
|
return testBeanList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTestBeanList(List<TestBean> testBeanList) {
|
||||||
|
this.testBeanList = testBeanList;
|
||||||
|
}
|
||||||
|
|
||||||
public List<List<Integer>> getListOfLists() {
|
public List<List<Integer>> getListOfLists() {
|
||||||
return listOfLists;
|
return listOfLists;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue