Search in sources :

Example 1 with GenericSetOfIntegerBean

use of org.springframework.tests.sample.beans.GenericSetOfIntegerBean in project spring-framework by spring-projects.

the class BeanWrapperGenericsTests method testGenericallyTypedSetOfIntegerBean.

@Test
public void testGenericallyTypedSetOfIntegerBean() throws Exception {
    GenericSetOfIntegerBean gb = new GenericSetOfIntegerBean();
    BeanWrapper bw = new BeanWrapperImpl(gb);
    bw.setPropertyValue("genericProperty", "10");
    bw.setPropertyValue("genericListProperty", new String[] { "20", "30" });
    assertEquals(new Integer(10), gb.getGenericProperty().iterator().next());
    assertEquals(new Integer(20), gb.getGenericListProperty().get(0).iterator().next());
    assertEquals(new Integer(30), gb.getGenericListProperty().get(1).iterator().next());
}
Also used : GenericSetOfIntegerBean(org.springframework.tests.sample.beans.GenericSetOfIntegerBean) Test(org.junit.Test)

Example 2 with GenericSetOfIntegerBean

use of org.springframework.tests.sample.beans.GenericSetOfIntegerBean in project spring-framework by spring-projects.

the class BeanFactoryGenericsTests method testGenericallyTypedSetOfIntegerBean.

@Test
public void testGenericallyTypedSetOfIntegerBean() throws Exception {
    DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
    new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource("genericBeanTests.xml", getClass()));
    GenericSetOfIntegerBean gb = (GenericSetOfIntegerBean) bf.getBean("setOfIntegerBean");
    assertEquals(new Integer(10), gb.getGenericProperty().iterator().next());
    assertEquals(new Integer(20), gb.getGenericListProperty().get(0).iterator().next());
    assertEquals(new Integer(30), gb.getGenericListProperty().get(1).iterator().next());
}
Also used : GenericSetOfIntegerBean(org.springframework.tests.sample.beans.GenericSetOfIntegerBean) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 GenericSetOfIntegerBean (org.springframework.tests.sample.beans.GenericSetOfIntegerBean)2 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1