org.springframework.tests.sample.beans.DependenciesBean Java Examples
The following examples show how to use
org.springframework.tests.sample.beans.DependenciesBean.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAutowireBeanByTypeWithTwoMatches() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertTrue(ex.getMessage().contains("test")); assertTrue(ex.getMessage().contains("spouse")); } }
Example #2
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAutowireWithSatisfiedJavaBeanDependency() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Rod"); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs); lbf.registerBeanDefinition("rod", bd); assertEquals(1, lbf.getBeanDefinitionCount()); // Depends on age, name and spouse (TestBean) Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); assertEquals(1, lbf.getBeanDefinitionCount()); DependenciesBean kerry = (DependenciesBean) registered; TestBean rod = (TestBean) lbf.getBean("rod"); assertSame(rod, kerry.getSpouse()); }
Example #3
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAutowireBeanByTypeWithTwoMatches() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertTrue(ex.getMessage().contains("test")); assertTrue(ex.getMessage().contains("spouse")); } }
Example #4
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testRegisterExistingSingletonWithAutowire() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Tony"); pvs.add("age", "48"); RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class); bd.setPropertyValues(pvs); bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS); bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE); lbf.registerBeanDefinition("test", bd); Object singletonObject = new TestBean(); lbf.registerSingleton("singletonObject", singletonObject); assertTrue(lbf.containsBean("singletonObject")); assertTrue(lbf.isSingleton("singletonObject")); assertEquals(TestBean.class, lbf.getType("singletonObject")); assertEquals(0, lbf.getAliases("singletonObject").length); DependenciesBean test = (DependenciesBean) lbf.getBean("test"); assertEquals(singletonObject, lbf.getBean("singletonObject")); assertEquals(singletonObject, test.getSpouse()); }
Example #5
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAutowireBeanByTypeWithIdenticalPriorityCandidates() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertNotNull("Exception should have cause", ex.getCause()); assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass()); assertTrue(ex.getMessage().contains("5")); // conflicting priority } }
Example #6
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAutowireBeanByTypeWithTwoPrimaryCandidates() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPrimary(true); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); bd2.setPrimary(true); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertNotNull("Exception should have cause", ex.getCause()); assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass()); } }
Example #7
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAutowireBeanByTypeWithTwoPrimaryCandidates() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPrimary(true); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); bd2.setPrimary(true); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertNotNull("Exception should have cause", ex.getCause()); assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass()); } }
Example #8
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAutowireBeanByTypeWithTwoMatchesAndParameterNameDiscovery() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertTrue(ex.getMessage().contains("test")); assertTrue(ex.getMessage().contains("spouse")); } }
Example #9
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAutowireBeanByTypeWithIdenticalPriorityCandidates() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertNotNull("Exception should have cause", ex.getCause()); assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass()); assertTrue(ex.getMessage().contains("5")); // conflicting priority } }
Example #10
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAutowireBeanByTypeWithTwoMatches() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertTrue(ex.getMessage().contains("test")); assertTrue(ex.getMessage().contains("spouse")); } }
Example #11
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAutowireBeanByTypeWithTwoPrimaryCandidates() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPrimary(true); RootBeanDefinition bd2 = new RootBeanDefinition(TestBean.class); bd2.setPrimary(true); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertNotNull("Exception should have cause", ex.getCause()); assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass()); } }
Example #12
Source File: XmlBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAutowireWithDefault() throws Exception { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(DEFAULT_AUTOWIRE_CONTEXT); DependenciesBean rod1 = (DependenciesBean) xbf.getBean("rod1"); // should have been autowired assertNotNull(rod1.getSpouse()); assertTrue(rod1.getSpouse().getName().equals("Kerry")); DependenciesBean rod2 = (DependenciesBean) xbf.getBean("rod2"); // should have been autowired assertNotNull(rod2.getSpouse()); assertTrue(rod2.getSpouse().getName().equals("Kerry")); try { xbf.getBean("rod3", DependenciesBean.class); fail("Must have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException expected) { } }
Example #13
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 6 votes |
@Test public void testAutowireBeanByTypeWithIdenticalPriorityCandidates() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(HighPriorityTestBean.class); lbf.registerBeanDefinition("test", bd); lbf.registerBeanDefinition("spouse", bd2); try { lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertNotNull("Exception should have cause", ex.getCause()); assertEquals("Wrong cause type", NoUniqueBeanDefinitionException.class, ex.getCause().getClass()); assertTrue(ex.getMessage().contains("5")); // conflicting priority } }
Example #14
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testRegisterExistingSingletonWithAutowire() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Tony"); pvs.add("age", "48"); RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class); bd.setPropertyValues(pvs); bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS); bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE); lbf.registerBeanDefinition("test", bd); Object singletonObject = new TestBean(); lbf.registerSingleton("singletonObject", singletonObject); assertTrue(lbf.containsBean("singletonObject")); assertTrue(lbf.isSingleton("singletonObject")); assertEquals(TestBean.class, lbf.getType("singletonObject")); assertEquals(0, lbf.getAliases("singletonObject").length); DependenciesBean test = (DependenciesBean) lbf.getBean("test"); assertEquals(singletonObject, lbf.getBean("singletonObject")); assertEquals(singletonObject, test.getSpouse()); }
Example #15
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testAutowireWithSatisfiedJavaBeanDependency() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Rod"); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs); lbf.registerBeanDefinition("rod", bd); assertEquals(1, lbf.getBeanDefinitionCount()); // Depends on age, name and spouse (TestBean) Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); assertEquals(1, lbf.getBeanDefinitionCount()); DependenciesBean kerry = (DependenciesBean) registered; TestBean rod = (TestBean) lbf.getBean("rod"); assertSame(rod, kerry.getSpouse()); }
Example #16
Source File: DefaultListableBeanFactoryTests.java From spring-analysis-note with MIT License | 6 votes |
@Test public void testRegisterExistingSingletonWithAutowire() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Tony"); pvs.add("age", "48"); RootBeanDefinition bd = new RootBeanDefinition(DependenciesBean.class); bd.setPropertyValues(pvs); bd.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS); bd.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE); lbf.registerBeanDefinition("test", bd); Object singletonObject = new TestBean(); lbf.registerSingleton("singletonObject", singletonObject); assertTrue(lbf.containsBean("singletonObject")); assertTrue(lbf.isSingleton("singletonObject")); assertEquals(TestBean.class, lbf.getType("singletonObject")); assertEquals(0, lbf.getAliases("singletonObject").length); DependenciesBean test = (DependenciesBean) lbf.getBean("test"); assertEquals(singletonObject, lbf.getBean("singletonObject")); assertEquals(singletonObject, test.getSpouse()); }
Example #17
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Test public void testAutowireWithSatisfiedJavaBeanDependency() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); MutablePropertyValues pvs = new MutablePropertyValues(); pvs.add("name", "Rod"); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); bd.setPropertyValues(pvs); lbf.registerBeanDefinition("rod", bd); assertEquals(1, lbf.getBeanDefinitionCount()); // Depends on age, name and spouse (TestBean) Object registered = lbf.autowire(DependenciesBean.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); assertEquals(1, lbf.getBeanDefinitionCount()); DependenciesBean kerry = (DependenciesBean) registered; TestBean rod = (TestBean) lbf.getBean("rod"); assertSame(rod, kerry.getSpouse()); }
Example #18
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testAutowireExistingBeanByNameWithNoDependencyCheck() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("spous", bd); DependenciesBean existingBean = new DependenciesBean(); lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); assertNull(existingBean.getSpouse()); }
Example #19
Source File: XmlBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testSatisfiedSimpleDependencyCheck() throws Exception { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_SIMPLE_DEP_CONTEXT); DependenciesBean a = (DependenciesBean) xbf.getBean("a"); assertEquals(a.getAge(), 33); }
Example #20
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@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"))); }
Example #21
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testAutowireExistingBeanByName() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); 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"); assertEquals(existingBean.getSpouse(), spouse); assertSame(spouse, BeanFactoryUtils.beanOfType(lbf, TestBean.class)); }
Example #22
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testAutowireExistingBeanByNameWithDependencyCheck() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("spous", bd); DependenciesBean existingBean = new DependenciesBean(); try { lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected } }
Example #23
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testAutowireBeanByTypeWithTwoMatchesAndPriority() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); lbf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE); RootBeanDefinition bd = new RootBeanDefinition(HighPriorityTestBean.class); RootBeanDefinition bd2 = new RootBeanDefinition(LowPriorityTestBean.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"))); }
Example #24
Source File: XmlBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testSatisfiedAllDependencyCheck() throws Exception { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_ALL_DEP_CONTEXT); DependenciesBean a = (DependenciesBean) xbf.getBean("a"); assertEquals(a.getAge(), 33); assertNotNull(a.getName()); assertNotNull(a.getSpouse()); }
Example #25
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testAutowireExistingBeanByNameWithNoDependencyCheck() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); RootBeanDefinition bd = new RootBeanDefinition(TestBean.class); lbf.registerBeanDefinition("spous", bd); DependenciesBean existingBean = new DependenciesBean(); lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false); assertNull(existingBean.getSpouse()); }
Example #26
Source File: XmlBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testSatisfiedObjectDependencyCheck() throws Exception { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(SATISFIED_OBJECT_DEP_CONTEXT); DependenciesBean a = (DependenciesBean) xbf.getBean("a"); assertNotNull(a.getSpouse()); assertEquals(xbf, a.getBeanFactory()); }
Example #27
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testAutowireExistingBeanByTypeWithNoDependencyCheck() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DependenciesBean existingBean = new DependenciesBean(); lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); assertNull(existingBean.getSpouse()); }
Example #28
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testAutowireExistingBeanByTypeWithDependencyCheck() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DependenciesBean existingBean = new DependenciesBean(); try { lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, true); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException expected) { } }
Example #29
Source File: DefaultListableBeanFactoryTests.java From java-technology-stack with MIT License | 5 votes |
@Test public void testAutowireExistingBeanByType() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); 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"); assertEquals(existingBean.getSpouse(), test); }
Example #30
Source File: DefaultListableBeanFactoryTests.java From spring4-understanding with Apache License 2.0 | 5 votes |
@Test public void testAutowireExistingBeanByTypeWithNoDependencyCheck() { DefaultListableBeanFactory lbf = new DefaultListableBeanFactory(); DependenciesBean existingBean = new DependenciesBean(); lbf.autowireBeanProperties(existingBean, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false); assertNull(existingBean.getSpouse()); }