@Test public void testCustomAnnotationRequiredFieldResourceInjectionFailsWhenNoDependencyFound() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationRequiredFieldResourceInjectionBean.class)); try { bf.getBean("customBean"); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertSame(CustomAnnotationRequiredFieldResourceInjectionBean.class, ex.getInjectionPoint().getField().getDeclaringClass()); } }
@Test public void testCustomAnnotationRequiredMethodResourceInjection() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationRequiredMethodResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); CustomAnnotationRequiredMethodResourceInjectionBean bean = (CustomAnnotationRequiredMethodResourceInjectionBean) bf.getBean("customBean"); assertSame(tb, bean.getTestBean()); }
@Test public void testCustomAnnotationRequiredFieldResourceInjection() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationRequiredFieldResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); CustomAnnotationRequiredFieldResourceInjectionBean bean = (CustomAnnotationRequiredFieldResourceInjectionBean) bf.getBean("customBean"); assertSame(tb, bean.getTestBean()); }
@Test public void testCustomAnnotationOptionalMethodResourceInjectionWhenNoDependencyFound() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationOptionalMethodResourceInjectionBean.class)); CustomAnnotationOptionalMethodResourceInjectionBean bean = (CustomAnnotationOptionalMethodResourceInjectionBean) bf.getBean("customBean"); assertNull(bean.getTestBean3()); assertNull(bean.getTestBean()); assertNull(bean.getTestBean2()); }
@Test public void testCustomAnnotationOptionalFieldResourceInjectionWhenNoDependencyFound() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationOptionalFieldResourceInjectionBean.class)); CustomAnnotationOptionalFieldResourceInjectionBean bean = (CustomAnnotationOptionalFieldResourceInjectionBean) bf.getBean("customBean"); assertNull(bean.getTestBean3()); assertNull(bean.getTestBean()); assertNull(bean.getTestBean2()); }
@Test public void testCustomAnnotationRequiredMethodResourceInjectionFailsWhenNoDependencyFound() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationRequiredMethodResourceInjectionBean.class)); try { bf.getBean("customBean"); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertSame(CustomAnnotationRequiredMethodResourceInjectionBean.class, ex.getInjectionPoint().getMethodParameter().getDeclaringClass()); } }
@Test public void testCustomAnnotationOptionalFieldResourceInjectionWhenMultipleDependenciesFound() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationOptionalFieldResourceInjectionBean.class)); TestBean tb1 = new TestBean(); bf.registerSingleton("testBean1", tb1); TestBean tb2 = new TestBean(); bf.registerSingleton("testBean2", tb2); try { bf.getBean("customBean"); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertSame(CustomAnnotationOptionalFieldResourceInjectionBean.class, ex.getInjectionPoint().getField().getDeclaringClass()); } }
@Test public void testCustomAnnotationRequiredFieldResourceInjectionFailsWhenMultipleDependenciesFound() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationRequiredFieldResourceInjectionBean.class)); TestBean tb1 = new TestBean(); bf.registerSingleton("testBean1", tb1); TestBean tb2 = new TestBean(); bf.registerSingleton("testBean2", tb2); try { bf.getBean("customBean"); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertSame(CustomAnnotationRequiredFieldResourceInjectionBean.class, ex.getInjectionPoint().getField().getDeclaringClass()); } }
@Test public void testCustomAnnotationOptionalFieldResourceInjection() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationOptionalFieldResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); CustomAnnotationOptionalFieldResourceInjectionBean bean = (CustomAnnotationOptionalFieldResourceInjectionBean) bf.getBean("customBean"); assertSame(tb, bean.getTestBean3()); assertNull(bean.getTestBean()); assertNull(bean.getTestBean2()); }
@Test public void testCustomAnnotationOptionalMethodResourceInjection() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationOptionalMethodResourceInjectionBean.class)); TestBean tb = new TestBean(); bf.registerSingleton("testBean", tb); CustomAnnotationOptionalMethodResourceInjectionBean bean = (CustomAnnotationOptionalMethodResourceInjectionBean) bf.getBean("customBean"); assertSame(tb, bean.getTestBean3()); assertNull(bean.getTestBean()); assertNull(bean.getTestBean2()); }
@Test public void testCustomAnnotationOptionalMethodResourceInjectionWhenMultipleDependenciesFound() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationOptionalMethodResourceInjectionBean.class)); TestBean tb1 = new TestBean(); bf.registerSingleton("testBean1", tb1); TestBean tb2 = new TestBean(); bf.registerSingleton("testBean2", tb2); try { bf.getBean("customBean"); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertSame(CustomAnnotationOptionalMethodResourceInjectionBean.class, ex.getInjectionPoint().getMethodParameter().getDeclaringClass()); } }
@Test public void testCustomAnnotationRequiredMethodResourceInjectionFailsWhenMultipleDependenciesFound() { bpp.setAutowiredAnnotationType(MyAutowired.class); bpp.setRequiredParameterName("optional"); bpp.setRequiredParameterValue(false); bf.registerBeanDefinition("customBean", new RootBeanDefinition( CustomAnnotationRequiredMethodResourceInjectionBean.class)); TestBean tb1 = new TestBean(); bf.registerSingleton("testBean1", tb1); TestBean tb2 = new TestBean(); bf.registerSingleton("testBean2", tb2); try { bf.getBean("customBean"); fail("Should have thrown UnsatisfiedDependencyException"); } catch (UnsatisfiedDependencyException ex) { // expected assertSame(CustomAnnotationRequiredMethodResourceInjectionBean.class, ex.getInjectionPoint().getMethodParameter().getDeclaringClass()); } }