RealObjectMaker { void injectObject(DependencyProvider dependencyProvider, Object instance, TypeToken<?> typeToken) { try { assignInjectableFields(dependencyProvider, instance, typeToken); callInjectableMethods(dependencyProvider, instance, typeToken); } catch (IllegalAccessException e) { throw new RuntimeException(e); } } RealObjectMaker(
      InjectionConfig.ConstructorSelector constructorSelector,
      List<Class<? extends Annotation>> injectFieldAnnotations,
      List<Class<? extends Annotation>> injectMethodAnnotations);   }
@Test public void testWithInjectOnlyDirectInject() { prep(Inject.class); TestClassWithInjectParams testObject = new TestClassWithInjectParams(); mRealObjectMaker.injectObject( mDependencyProvider, testObject, TypeToken.of(TestClassWithInjectParams.class)); assertTestObjectNormal(testObject, TestClassWithInjectParams.class); verifyDependencyProviderCalls(runnableKey, runnableProviderKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }
@Test public void testWithWeirdInjectAnnotationsDirectInject() { prep(Inject.class, Singleton.class); TestClassWithWeirdInjectAnnotations testObject = new TestClassWithWeirdInjectAnnotations(); mRealObjectMaker.injectObject( mDependencyProvider, testObject, TypeToken.of(TestClassWithWeirdInjectAnnotations.class)); assertTestObjectNormal(testObject, TestClassWithWeirdInjectAnnotations.class); verifyDependencyProviderCalls(runnableKey, runnableProviderKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }
@Test public void testSubclassDirectInject() { prep(Inject.class); TestSubclass testObject = new TestSubclass(); mRealObjectMaker.injectObject( mDependencyProvider, testObject, TypeToken.of(TestSubclass.class)); assertTestObjectNormal(testObject, TestSubclass.class); verifyDependencyProviderCalls(runnableKey, runnableProviderKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }
@Test public void testMethodDirectInjection() { prep(Inject.class); TestMethodInjection testObject = new TestMethodInjection(); mRealObjectMaker.injectObject( mDependencyProvider, testObject, TypeToken.of(TestMethodInjection.class)); assertTestObjectNormal(testObject, TestMethodInjection.class); verifyDependencyProviderCalls(runnableKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); }
@Test public void testSubclassMethodDirectInject() { prep(Inject.class); TestMethodInjectionSubclass testObject = new TestMethodInjectionSubclass(); mRealObjectMaker.injectObject(mDependencyProvider, testObject, TypeToken.of(TestMethodInjectionSubclass.class)); assertTestObjectNormal(testObject, TestMethodInjectionSubclass.class); InOrder inOrder = inOrder(mDependencyProvider); inOrder.verify(mDependencyProvider).get(runnableKey); inOrder.verify(mDependencyProvider).get(runnableProviderKey); inOrder.verifyNoMoreInteractions(); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }