use of org.springframework.beans.testfixture.beans.DerivedTestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method prototypeWithArrayConversionForFactoryMethod.
@Test
void prototypeWithArrayConversionForFactoryMethod() {
List<String> list = ManagedList.of("myName", "myBeanName");
RootBeanDefinition bd = new RootBeanDefinition(DerivedTestBean.class);
bd.setScope(BeanDefinition.SCOPE_PROTOTYPE);
bd.setFactoryMethodName("create");
bd.getConstructorArgumentValues().addGenericArgumentValue(list);
lbf.registerBeanDefinition("test", bd);
DerivedTestBean tb = (DerivedTestBean) lbf.getBean("test");
assertThat(tb.getName()).isEqualTo("myName");
assertThat(tb.getBeanName()).isEqualTo("myBeanName");
DerivedTestBean tb2 = (DerivedTestBean) lbf.getBean("test");
assertThat(tb != tb2).isTrue();
assertThat(tb2.getName()).isEqualTo("myName");
assertThat(tb2.getBeanName()).isEqualTo("myBeanName");
}
use of org.springframework.beans.testfixture.beans.DerivedTestBean in project spring-framework by spring-projects.
the class BeanUtilsTests method copyPropertiesWithDifferentTypes2.
@Test
void copyPropertiesWithDifferentTypes2() throws Exception {
TestBean tb = new TestBean();
tb.setName("rod");
tb.setAge(32);
tb.setTouchy("touchy");
DerivedTestBean tb2 = new DerivedTestBean();
assertThat(tb2.getName() == null).as("Name empty").isTrue();
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
BeanUtils.copyProperties(tb, tb2);
assertThat(tb2.getName().equals(tb.getName())).as("Name copied").isTrue();
assertThat(tb2.getAge() == tb.getAge()).as("Age copied").isTrue();
assertThat(tb2.getTouchy().equals(tb.getTouchy())).as("Touchy copied").isTrue();
}
use of org.springframework.beans.testfixture.beans.DerivedTestBean in project spring-framework by spring-projects.
the class BeanUtilsTests method copyPropertiesWithDifferentTypes1.
@Test
void copyPropertiesWithDifferentTypes1() throws Exception {
DerivedTestBean tb = new DerivedTestBean();
tb.setName("rod");
tb.setAge(32);
tb.setTouchy("touchy");
TestBean tb2 = new TestBean();
assertThat(tb2.getName() == null).as("Name empty").isTrue();
assertThat(tb2.getAge() == 0).as("Age empty").isTrue();
assertThat(tb2.getTouchy() == null).as("Touchy empty").isTrue();
BeanUtils.copyProperties(tb, tb2);
assertThat(tb2.getName().equals(tb.getName())).as("Name copied").isTrue();
assertThat(tb2.getAge() == tb.getAge()).as("Age copied").isTrue();
assertThat(tb2.getTouchy().equals(tb.getTouchy())).as("Touchy copied").isTrue();
}
use of org.springframework.beans.testfixture.beans.DerivedTestBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method createBeanWithDisposableBean.
@Test
void createBeanWithDisposableBean() {
DerivedTestBean tb = lbf.createBean(DerivedTestBean.class);
assertThat(tb.getBeanFactory()).isSameAs(lbf);
lbf.destroyBean(tb);
assertThat(tb.wasDestroyed()).isTrue();
}
use of org.springframework.beans.testfixture.beans.DerivedTestBean in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method inheritanceWithDifferentClass.
@Test
void inheritanceWithDifferentClass() {
DefaultListableBeanFactory parent = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(parent).loadBeanDefinitions(PARENT_CONTEXT);
DefaultListableBeanFactory child = new DefaultListableBeanFactory(parent);
new XmlBeanDefinitionReader(child).loadBeanDefinitions(CHILD_CONTEXT);
assertThat(child.getType("inheritsWithClass")).isEqualTo(DerivedTestBean.class);
DerivedTestBean inherits = (DerivedTestBean) child.getBean("inheritsWithDifferentClass");
// Name property value is overridden
assertThat(inherits.getName().equals("override")).isTrue();
// Age property is inherited from bean in parent factory
assertThat(inherits.getAge() == 1).isTrue();
assertThat(inherits.wasInitialized()).isTrue();
}
Aggregations