@Test public void testGet() throws Exception { Injector mockInjector = createMock(Injector.class); Object c1 = new Object(); Object c2 = new Object(); final AtomicBoolean postProcessCalled = new AtomicBoolean(false); expect(mockInjector.getInstance(keyC1)).andReturn(c1); expect(mockInjector.getInstance(keyC2)).andReturn(c2); mockInjector.injectMembers(anyObject(SomeInjectedClass.class)); replay(mockInjector); AbstractInjectionProvider<SomeInjectedClass> underTest = new AbstractInjectionProvider<SomeInjectedClass>(Key.get(SomeInjectedClass.class)) { @Override protected SomeInjectedClass postProcess(SomeInjectedClass someInjectedClass) { postProcessCalled.set(true); return super.postProcess(someInjectedClass); } }; underTest.injector = mockInjector; SomeInjectedClass got = underTest.get(); assertEquals("Wrong parameter passed to constructor (index 0).", c1, got.c1); assertEquals("Wrong parameter passed to constructor (index 1).", c2, got.c2); assertTrue("postProcess method was not called.", postProcessCalled.get()); verify(mockInjector); }
public T get() { Constructor<T> constructor = getConstructor(); Object[] params = new Object[constructor.getParameterTypes().length]; for (Dependency<?> dependency : constructorInjectionPoint.getDependencies()) { params[dependency.getParameterIndex()] = injector.getInstance(dependency.getKey()); } T t; try { t = constructor.newInstance(params); } catch (Exception e) { throw new ProvisionException("Could not instantiate " + key + "", e); } injector.injectMembers(t); return postProcess(t); }
AbstractInjectionProvider implements ProviderWithDependencies<T> { public T get() { Constructor<T> constructor = getConstructor(); Object[] params = new Object[constructor.getParameterTypes().length]; for (Dependency<?> dependency : constructorInjectionPoint.getDependencies()) { params[dependency.getParameterIndex()] = injector.getInstance(dependency.getKey()); } T t; try { t = constructor.newInstance(params); } catch (Exception e) { throw new ProvisionException("Could not instantiate " + key + "", e); } injector.injectMembers(t); return postProcess(t); } }
AbstractInjectionProvider implements ProviderWithDependencies<T> { public T get() { Constructor<T> constructor = getConstructor(); Object[] params = new Object[constructor.getParameterTypes().length]; for (Dependency<?> dependency : constructorInjectionPoint.getDependencies()) { params[dependency.getParameterIndex()] = injector.getInstance(dependency.getKey()); } T t; try { t = constructor.newInstance(params); } catch (Exception e) { throw new ProvisionException("Could not instantiate " + key + "", e); } injector.injectMembers(t); return postProcess(t); } AbstractInjectionProvider(Key<T> key); }
AbstractInjectionProvider implements ProviderWithDependencies<T> { public T get() { Constructor<T> constructor = getConstructor(); Object[] params = new Object[constructor.getParameterTypes().length]; for (Dependency<?> dependency : constructorInjectionPoint.getDependencies()) { params[dependency.getParameterIndex()] = injector.getInstance(dependency.getKey()); } T t; try { t = constructor.newInstance(params); } catch (Exception e) { throw new ProvisionException("Could not instantiate " + key + "", e); } injector.injectMembers(t); return postProcess(t); } AbstractInjectionProvider(Key<T> key); T get(); Set<Dependency<?>> getDependencies(); }
AbstractInjectionProvider implements ProviderWithDependencies<T> { public T get() { Constructor<T> constructor = getConstructor(); Object[] params = new Object[constructor.getParameterTypes().length]; for (Dependency<?> dependency : constructorInjectionPoint.getDependencies()) { params[dependency.getParameterIndex()] = injector.getInstance(dependency.getKey()); } T t; try { t = constructor.newInstance(params); } catch (Exception e) { throw new ProvisionException("Could not instantiate " + key + "", e); } injector.injectMembers(t); return postProcess(t); } AbstractInjectionProvider(Key<T> key); T get(); Set<Dependency<?>> getDependencies();  }