use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method autowireWithDefault.
@Test
void autowireWithDefault() {
DefaultListableBeanFactory xbf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_AUTOWIRE_CONTEXT);
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
// should have been autowired
assertThat(rod1.getSpouse()).isNotNull();
assertThat(rod1.getSpouse().getName().equals("Kerry")).isTrue();
DependenciesBean rod2 = (DependenciesBean) xbf.getBean("rod2");
// should have been autowired
assertThat(rod2.getSpouse()).isNotNull();
assertThat(rod2.getSpouse().getName().equals("Kerry")).isTrue();
}
use of org.springframework.beans.testfixture.beans.DependenciesBean in project spring-framework by spring-projects.
the class XmlBeanFactoryTests method doTestAutowire.
private void doTestAutowire(DefaultListableBeanFactory xbf) {
DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1");
TestBean kerry = (TestBean) xbf.getBean("spouse");
// should have been autowired
assertThat(rod1.getSpouse()).isEqualTo(kerry);
DependenciesBean rod1a = (DependenciesBean) xbf.getBean("rod1a");
// should have been autowired
assertThat(rod1a.getSpouse()).isEqualTo(kerry);
DependenciesBean rod2 = (DependenciesBean) xbf.getBean("rod2");
// should have been autowired
assertThat(rod2.getSpouse()).isEqualTo(kerry);
DependenciesBean rod2a = (DependenciesBean) xbf.getBean("rod2a");
// should have been set explicitly
assertThat(rod2a.getSpouse()).isEqualTo(kerry);
ConstructorDependenciesBean rod3 = (ConstructorDependenciesBean) xbf.getBean("rod3");
IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
// should have been autowired
assertThat(rod3.getSpouse1()).isEqualTo(kerry);
assertThat(rod3.getSpouse2()).isEqualTo(kerry);
assertThat(rod3.getOther()).isEqualTo(other);
ConstructorDependenciesBean rod3a = (ConstructorDependenciesBean) xbf.getBean("rod3a");
// should have been autowired
assertThat(rod3a.getSpouse1()).isEqualTo(kerry);
assertThat(rod3a.getSpouse2()).isEqualTo(kerry);
assertThat(rod3a.getOther()).isEqualTo(other);
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() -> xbf.getBean("rod4", ConstructorDependenciesBean.class));
DependenciesBean rod5 = (DependenciesBean) xbf.getBean("rod5");
// Should not have been autowired
assertThat((Object) rod5.getSpouse()).isNull();
BeanFactory appCtx = (BeanFactory) xbf.getBean("childAppCtx");
assertThat(appCtx.containsBean("rod1")).isTrue();
assertThat(appCtx.containsBean("jenny")).isTrue();
}
Aggregations