use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireWithSatisfiedJavaBeanDependency.
@Test
void autowireWithSatisfiedJavaBeanDependency() {
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("name", "Rod");
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPropertyValues(pvs);
lbf.registerBeanDefinition("rod", bd);
assertThat(lbf.getBeanDefinitionCount()).isEqualTo(1);
// Depends on age, name and spouse (TestBean)
Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertThat(lbf.getBeanDefinitionCount()).isEqualTo(1);
DependenciesBean kerry = (DependenciesBean) registered;
TestBean rod = (TestBean) lbf.getBean("rod");
assertThat(kerry.getSpouse()).isSameAs(rod);
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireExistingBeanByTypeWithDependencyCheck.
@Test
void autowireExistingBeanByTypeWithDependencyCheck() {
DependenciesBean existingBean = new DependenciesBean();
assertThatExceptionOfType(UnsatisfiedDependencyException.class).isThrownBy(() -> lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true));
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireExistingBeanByName.
@Test
void autowireExistingBeanByName() {
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spouse", bd);
DependenciesBean existingBean = new DependenciesBean();
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
TestBean spouse = (TestBean) lbf.getBean("spouse");
assertThat(spouse).isEqualTo(existingBean.getSpouse());
assertThat(BeanFactoryUtils.beanOfType(lbf, TestBean.class)).isSameAs(spouse);
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireExistingBeanByTypeWithNoDependencyCheck.
@Test
void autowireExistingBeanByTypeWithNoDependencyCheck() {
DependenciesBean existingBean = new DependenciesBean();
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
assertThat(existingBean.getSpouse()).isNull();
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireBeanByNameWithNoDependencyCheck.
@Test
void autowireBeanByNameWithNoDependencyCheck() {
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spous", bd);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
assertThat(bean.getSpouse()).isNull();
}
Aggregations