use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByNameWithNoDependencyCheck.
@Test
public void testAutowireBeanByNameWithNoDependencyCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(TestBean.class);
lbf.registerBeanDefinition("spous", bd);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
assertNull(bean.getSpouse());
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByName.
@Test
public void testAutowireBeanByName() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
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");
assertEquals(spouse, bean.getSpouse());
assertTrue(BeanFactoryUtils.beanOfType(lbf, TestBean.class) == spouse);
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByTypePrimaryTakesPrecedenceOverPriority.
@Test
public void testAutowireBeanByTypePrimaryTakesPrecedenceOverPriority() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class);
RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class);
bd2.setPrimary(true);
lbf.registerBeanDefinition("test", bd);
lbf.registerBeanDefinition("spouse", bd2);
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true);
assertThat(bean.getSpouse(), equalTo(lbf.getBean("spouse")));
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByTypeWithNoDependencyCheck.
@Test
public void testAutowireBeanByTypeWithNoDependencyCheck() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
DependenciesBean bean = (DependenciesBean) lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
assertNull(bean.getSpouse());
}
use of org.springframework.tests.sample.beans.DependenciesBean in project spring-framework by spring-projects.
the class DefaultListableBeanFactoryTests method testAutowireBeanByTypeWithTwoMatchesAndOnePrimary.
@Test
public void testAutowireBeanByTypeWithTwoMatchesAndOnePrimary() {
DefaultListableBeanFactory lbf = new DefaultListableBeanFactory();
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(), equalTo(lbf.getBean("test")));
}
Aggregations