use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireExistingBeanByType.
@Test
void autowireExistingBeanByType() {
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("test", bd);
DependenciesBean existingBean = new DependenciesBean();
lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
TestBean test = (TestBean) lbf.getBean("test");
assertThat(test).isEqualTo(existingBean.getSpouse());
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireBeanByName.
@Test
void autowireBeanByName() {
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spouse", bd);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true);
TestBean spouse = (TestBean) lbf.getBean("spouse");
assertThat(bean.getSpouse()).isEqualTo(spouse);
assertThat(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse).isTrue();
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireBeanByTypeWithNoDependencyCheck.
@Test
void autowireBeanByTypeWithNoDependencyCheck() {
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
assertThat(bean.getSpouse()).isNull();
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireBeanByType.
@Test
void autowireBeanByType() {
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("test", bd);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
TestBean test = (TestBean) lbf.getBean("test");
assertThat(bean.getSpouse()).isEqualTo(test);
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method autowireBeanByTypeWithTwoMatchesAndOnePrimary.
@Test
void autowireBeanByTypeWithTwoMatchesAndOnePrimary() {
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
bd.setPrimary(true);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("test", bd);
lbf.registerBeanDefinition("spouse", bd2);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertThat(bean.getSpouse()).isEqualTo(lbf.getBean("test"));
}
Aggregations