RealObjectMaker { <T> T createObject(DependencyProvider dependencyProvider, TypeToken<T> typeToken) { try { return createObjectInternal(dependencyProvider, typeToken); } catch (IllegalAccessException | InvocationTargetException | InstantiationException e) { throw new RuntimeException(e); } } RealObjectMaker(
      InjectionConfig.ConstructorSelector constructorSelector,
      List<Class<? extends Annotation>> injectFieldAnnotations,
      List<Class<? extends Annotation>> injectMethodAnnotations);   }
@Test public void testWithConstructorOnly() { prep(); TestClassWithConstructorOnly testObject = mRealObjectMaker.createObject( mDependencyProvider, TypeToken.of(TestClassWithConstructorOnly.class)); assertTestObjectNormal(testObject, TestClassWithConstructorOnly.class); verifyDependencyProviderCalls(runnableKey, runnableProviderKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }
@Test public void testWithInjectOnly() { prep(Inject.class); TestClassWithInjectParams testObject = mRealObjectMaker.createObject( mDependencyProvider, TypeToken.of(TestClassWithInjectParams.class)); assertTestObjectNormal(testObject, TestClassWithInjectParams.class); verifyDependencyProviderCalls(runnableKey, runnableProviderKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }
@Test public void testWithConstructorAndInjectMixed() { prep(Inject.class); TestConstructorAndInject testObject = mRealObjectMaker.createObject( mDependencyProvider, TypeToken.of(TestConstructorAndInject.class)); assertTestObjectNormal(testObject, TestConstructorAndInject.class); verifyDependencyProviderCalls(runnableKey, runnableProviderKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }
@Test public void testWithWeirdInjectAnnotations() { prep(Inject.class, Singleton.class); TestClassWithWeirdInjectAnnotations testObject = mRealObjectMaker.createObject( mDependencyProvider, TypeToken.of(TestClassWithWeirdInjectAnnotations.class)); assertTestObjectNormal(testObject, TestClassWithWeirdInjectAnnotations.class); verifyDependencyProviderCalls(runnableKey, runnableProviderKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }
@Test public void testSubclassInject() { prep(Inject.class); TestSubclass testObject = mRealObjectMaker.createObject( mDependencyProvider, TypeToken.of(TestSubclass.class)); assertTestObjectNormal(testObject, TestSubclass.class); verifyDependencyProviderCalls(runnableKey, runnableProviderKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); assertThat(testObject.mRunnableProvider).isEqualTo(mRunnableProviderMock); }
@Test public void testMethodInjection() { prep(Inject.class); TestMethodInjection testObject = mRealObjectMaker.createObject( mDependencyProvider, TypeToken.of(TestMethodInjection.class)); assertTestObjectNormal(testObject, TestMethodInjection.class); verifyDependencyProviderCalls(runnableKey); assertThat(testObject.mRunnable).isEqualTo(mRunnableMock); }
@Test public void testSubclassMethodInject() { prep(Inject.class); TestMethodInjectionSubclass testObject = mRealObjectMaker.createObject( mDependencyProvider, 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); }