@Override public void bind(Injector builder) { // Bind provider builder.declareProvider( declaredType, getScope(), getQualifiers(), implementationType); } };
@Override public void bind(Injector builder) { // Bind provider builder.declareProvider( declaredType, getScope(), getQualifiers(), implementationType); } };
@Test public void test() throws Exception { init(); bootstrap.declareProvider(Bean.class, null, null, BeanProducer.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.dependency); } }
@Test public void test() throws Exception { init(); bootstrap.declareProvider(Bean.class, null, null, BeanProvider.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.dependency); }
@Test public void test() throws Exception { init(); bootstrap.declareProvider(Bean.class, null, null, BeanProvider.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.dependency); }
@Test public void test() throws Exception { init(); bootstrap.declareProvider(Bean.class, null, null, BeanProducer.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.dependency); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, (Class<Injected>)null); bootstrap.declareProvider(Bean.class, null, null, RedBeanProvider.class); bootstrap.declareProvider(Bean.class, null, null, GreenBeanProvider.class); boot(); // Injected beanObject = getBean(Injected.class); assertNotNull(beanObject); assertNotNull(beanObject.getRed()); assertEquals(Bean.RED, beanObject.getRed()); assertNotNull(beanObject.getGreen()); assertEquals(Bean.GREEN, beanObject.getGreen()); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, (Class<Injected>)null); bootstrap.declareProvider(Bean.class, null, null, RedBeanProvider.class); bootstrap.declareProvider(Bean.class, null, null, GreenBeanProvider.class); boot(); // Injected beanObject = getBean(Injected.class); assertNotNull(beanObject); assertNotNull(beanObject.getRed()); assertEquals(Bean.RED, beanObject.getRed()); assertNotNull(beanObject.getGreen()); assertEquals(Bean.GREEN, beanObject.getGreen()); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean.class, Scope.REQUEST, null, BeanProvider.class); boot(Scope.REQUEST); // beginScoping(); try { assertEquals(0, scopingContext.getEntries().size()); Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.injected); String value = injected.injected.getValue(); assertEquals(1, scopingContext.getEntries().size()); ScopedKey key = scopingContext.getEntries().keySet().iterator().next(); assertEquals(Scope.REQUEST, key.getScope()); Bean scoped = (Bean)scopingContext.getEntries().get(key).get(); assertEquals(scoped.getValue(), value); assertSame(scoped, BeanProvider.bean); } finally { endScoping(); } } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.BLUE)), ColorlessProvider.class); bootstrap.declareProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.RED)), ColorlessProvider.class); bootstrap.declareProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.GREEN)), GreenProvider.class); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.blue); assertNotNull(injected.red); assertNotNull(injected.green); assertNotSame(injected.blue.getId(), injected.red.getId()); assertNotSame(injected.green.getId(), injected.red.getId()); assertNotSame(injected.blue.getId(), injected.green.getId()); assertInstanceOf(Bean.class, injected.blue); assertInstanceOf(Bean.class, injected.red); assertInstanceOf(Bean.Green.class, injected.green); assertNotInstanceOf(Bean.Green.class, injected.blue); assertNotInstanceOf(Bean.Green.class, injected.red); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean1.class, null, null, Bean1Provider.class); bootstrap.declareProvider(Bean2.class, null, null, Bean2Provider.class); bootstrap.addFileSystem(fs); boot(); // Bean1 productExt1 = getBean(Bean1.class); assertNotNull(productExt1); // Bean2 productExt2 = getBean(Bean2.class); assertNotNull(productExt2); // Injected productInjected = getBean(Injected.class); assertNotNull(productInjected); assertNotNull(productInjected.productExt1); assertNotNull(productInjected.productExt2); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.BLUE)), ColorlessProvider.class); bootstrap.declareProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.RED)), ColorlessProvider.class); bootstrap.declareProvider(Bean.class, null, Collections.<Annotation>singleton(new ColorizedLiteral(Color.GREEN)), GreenProvider.class); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.blue); assertNotNull(injected.red); assertNotNull(injected.green); assertNotSame(injected.blue.getId(), injected.red.getId()); assertNotSame(injected.green.getId(), injected.red.getId()); assertNotSame(injected.blue.getId(), injected.green.getId()); assertInstanceOf(Bean.class, injected.blue); assertInstanceOf(Bean.class, injected.red); assertInstanceOf(Bean.Green.class, injected.green); assertNotInstanceOf(Bean.Green.class, injected.blue); assertNotInstanceOf(Bean.Green.class, injected.red); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean1.class, null, null, Bean1Provider.class); bootstrap.declareProvider(Bean2.class, null, null, Bean2Provider.class); bootstrap.addFileSystem(fs); boot(); // Bean1 productExt1 = getBean(Bean1.class); assertNotNull(productExt1); // Bean2 productExt2 = getBean(Bean2.class); assertNotNull(productExt2); // Injected productInjected = getBean(Injected.class); assertNotNull(productInjected); assertNotNull(productInjected.productExt1); assertNotNull(productInjected.productExt2); } }
@Test public void test() throws Exception { init(); bootstrap.declareProvider(Bean.class, null, null, BeanProvider.class); boot(Scope.REQUEST); // beginScoping(); try { Bean bean = getBean(Bean.class); assertNotNull(bean); assertNotNull(bean.provider); } finally { endScoping(); } } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean.class, Scope.REQUEST, null, BeanProvider.class); boot(Scope.REQUEST); // beginScoping(); try { assertEquals(0, scopingContext.getEntries().size()); Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.injected); String value = injected.injected.getValue(); assertEquals(1, scopingContext.getEntries().size()); ScopedKey key = scopingContext.getEntries().keySet().iterator().next(); assertEquals(Scope.REQUEST, key.getScope()); Bean scoped = (Bean)scopingContext.getEntries().get(key).get(); assertEquals(scoped.getValue(), value); assertSame(scoped, BeanProvider.bean); } finally { endScoping(); } } }
@Test public void test() throws Exception { init(); bootstrap.declareProvider(Bean.class, null, null, BeanProvider.class); boot(Scope.REQUEST); // beginScoping(); try { Bean bean = getBean(Bean.class); assertNotNull(bean); assertNotNull(bean.provider); } finally { endScoping(); } } }
@Test public void test() throws Exception { init(); Dependency dependency = new Dependency(); bootstrap.bindBean(Dependency.class, null, dependency); bootstrap.declareProvider(Bean.class, null, null, DependencyProvider.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.product); assertSame(dependency, injected.product.dependency); } }
@Test public void test() throws Exception { init(); Dependency dependency = new Dependency(); bootstrap.bindBean(Dependency.class, null, dependency); bootstrap.declareProvider(Bean.class, null, null, DependencyProvider.class); bootstrap.declareBean(Injected.class, null, null, null); boot(); // Injected injected = getBean(Injected.class); assertNotNull(injected); assertNotNull(injected.product); assertSame(dependency, injected.product.dependency); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean.class, null, null, FooBeanProvider.class); bootstrap.declareProvider(Bean.class, null, null, BarBeanProvider.class); boot(); // Injected beanObject = getBean(Injected.class); assertNotNull(beanObject); assertNotNull(beanObject.getFoo()); assertEquals(Bean.FOO, beanObject.getFoo()); assertNotNull(beanObject.getBar()); assertEquals(Bean.BAR, beanObject.getBar()); // Object foo = getBean("foo"); assertNotNull(foo); // assertNull(mgr.resolveBean("juu")); } }
@Test public void test() throws Exception { init(); bootstrap.declareBean(Injected.class, null, null, null); bootstrap.declareProvider(Bean.class, null, null, FooBeanProvider.class); bootstrap.declareProvider(Bean.class, null, null, BarBeanProvider.class); boot(); // Injected beanObject = getBean(Injected.class); assertNotNull(beanObject); assertNotNull(beanObject.getFoo()); assertEquals(Bean.FOO, beanObject.getFoo()); assertNotNull(beanObject.getBar()); assertEquals(Bean.BAR, beanObject.getBar()); // Object foo = getBean("foo"); assertNotNull(foo); // assertNull(mgr.resolveBean("juu")); } }