use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class DirectFieldAccessorTests method withShadowedField.
@Test
public void withShadowedField() throws Exception {
final StringBuilder sb = new StringBuilder();
@SuppressWarnings("serial") TestBean target = new TestBean() {
@SuppressWarnings("unused")
StringBuilder name = sb;
};
DirectFieldAccessor dfa = createAccessor(target);
assertEquals(StringBuilder.class, dfa.getPropertyType("name"));
assertEquals(sb, dfa.getPropertyValue("name"));
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class BeanUtilsTests method testCopyPropertiesWithDifferentTypes2.
@Test
public void testCopyPropertiesWithDifferentTypes2() throws Exception {
TestBean tb = new TestBean();
tb.setName("rod");
tb.setAge(32);
tb.setTouchy("touchy");
DerivedTestBean tb2 = new DerivedTestBean();
assertTrue("Name empty", tb2.getName() == null);
assertTrue("Age empty", tb2.getAge() == 0);
assertTrue("Touchy empty", tb2.getTouchy() == null);
BeanUtils.copyProperties(tb, tb2);
assertTrue("Name copied", tb2.getName().equals(tb.getName()));
assertTrue("Age copied", tb2.getAge() == tb.getAge());
assertTrue("Touchy copied", tb2.getTouchy().equals(tb.getTouchy()));
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class PropertyPathFactoryBeanTests method testPropertyPathFactoryBeanAsInnerBean.
@Test
public void testPropertyPathFactoryBeanAsInnerBean() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
TestBean spouse = (TestBean) xbf.getBean("otb.spouse");
TestBean tbWithInner = (TestBean) xbf.getBean("tbWithInner");
assertSame(spouse, tbWithInner.getSpouse());
assertTrue(!tbWithInner.getFriends().isEmpty());
assertSame(spouse, tbWithInner.getFriends().iterator().next());
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class PropertyPathFactoryBeanTests method testPropertyPathFactoryBeanWithPrototypeResult.
@Test
public void testPropertyPathFactoryBeanWithPrototypeResult() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(CONTEXT);
assertNull(xbf.getType("tb.spouse"));
assertEquals(TestBean.class, xbf.getType("propertyPath3"));
Object result1 = xbf.getBean("tb.spouse");
Object result2 = xbf.getBean("propertyPath3");
Object result3 = xbf.getBean("propertyPath3");
assertTrue(result1 instanceof TestBean);
assertTrue(result2 instanceof TestBean);
assertTrue(result3 instanceof TestBean);
assertEquals(11, ((TestBean) result1).getAge());
assertEquals(11, ((TestBean) result2).getAge());
assertEquals(11, ((TestBean) result3).getAge());
assertTrue(result1 != result2);
assertTrue(result1 != result3);
assertTrue(result2 != result3);
}
use of org.springframework.tests.sample.beans.TestBean in project spring-framework by spring-projects.
the class PropertyPlaceholderConfigurerTests method trimValuesIsOffByDefault.
@Test
public void trimValuesIsOffByDefault() {
PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
getModifiableSystemEnvironment().put("my.name", " myValue ");
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
bf.registerBeanDefinition("testBean", rootBeanDefinition(TestBean.class).addPropertyValue("name", "${my.name}").getBeanDefinition());
ppc.postProcessBeanFactory(bf);
assertThat(bf.getBean(TestBean.class).getName(), equalTo(" myValue "));
getModifiableSystemEnvironment().remove("my.name");
}
Aggregations