title: DaggerMock not injecting Mock objects in Espresso test
body: <p>Unsuccessfully trying to get an implementation of <a href="https://github.com/fabioCollini/DaggerMock" rel="nofollow noreferrer">DaggerMock</a> running on my Espresso test. I've copied the sample almost exactly but it will always use a real implementation of <code>MainPresenter</code> rather than a mock implementation.</p>
  
  <p>EspressoRule (copied exactly from <a href="https://github.com/fabioCollini/DaggerMock/blob/master/RealWorldApp/src/androidTest/java/it/cosenonjaviste/daggermock/realworldapp/EspressoDaggerMockRule.java" rel="nofollow noreferrer">real world sample</a>):</p>
  
  <pre><code>public class EspressoDaggerMockRule extends DaggerMockRule&lt;AppComponent&gt;
  {
      public EspressoDaggerMockRule()
      {
          super(AppComponent.class, new AppModule(getApp()));
          set(new ComponentSetter&lt;AppComponent&gt;()
          {
              @Override
              public void setComponent(AppComponent appComponent)
              {
                  getApp().setComponent(appComponent);
              }
          });
      }
  
      private static App getApp()
      {
          return (App) InstrumentationRegistry.getInstrumentation().getTargetContext().getApplicationContext();
      }
  }
  </code></pre>
  
  <p>Espresso test:</p>
  
  <pre><code>public class MainActivityTest
  {
      @Rule
      public EspressoDaggerMockRule rule = new EspressoDaggerMockRule();
  
      @Rule
      public ActivityTestRule&lt;MainActivity&gt; mActivityTestRule = new ActivityTestRule&lt;&gt;(MainActivity.class, false, false);
  
      @Mock MainPresenter presenter;
  
      @Test
      public void test() throws InterruptedException
      {
          final MainActivity activity = mActivityTestRule.launchActivity(null);
          // presenter in this test class will be mocked but the presenter in activity will be real
  
          Thread.sleep(1000);
      }
  }
  </code></pre>
  
  <p>MainActivity:</p>
  
  <pre><code>public class MainActivity extends BaseActivity implements MainContract.View
  {
      @Inject MainPresenter mainPresenter;
  
      @Override
      protected void onCreate(Bundle savedInstanceState)
      {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
      }
  
      @Override
      public void setupComponent(AppComponent appComponent)
      {
          appComponent
                  .mainActivityComponentBuilder()
                  .mainActivityModule(new MainModule(this))
                  .build()
                  .inject(this);
      }
  }
  </code></pre>
  
  <p>MainComponent:</p>
  
  <pre><code>@Subcomponent(modules = {MainModule.class})
  public interface MainComponent
  {
      void inject(MainActivity mainActivity);
  
      @Subcomponent.Builder
      interface Builder
      {
          Builder mainActivityModule(MainModule module);
  
          MainComponent build();
      }
  }
  </code></pre>
  
  <p>MainModule:</p>
  
  <pre><code>@Module
  public class MainModule
  {
      private MainActivity mainActivity;
  
      public MainModule(MainActivity mainActivity)
      {
          this.mainActivity = mainActivity;
      }
  
      @Provides
      public MainContract.View mainView()
      {
          return mainActivity;
      }
  
      @Provides
      public MainPresenter mainPresenter()
      {
          return new MainPresenter(mainActivity);
      }
  }
  </code></pre>
  
  <p>AppComponent</p>
  
  <pre><code>@Singleton
  @Component(modules = {AppModule.class})
  public interface AppComponent
  {
      MainComponent.Builder mainActivityComponentBuilder();
  }
  </code></pre>
  
  <p>App:</p>
  
  <pre><code>public class App extends Application
  {
      public static AppComponent appComponent;
  
      @Override
      public void onCreate()
      {
          super.onCreate();
          setupGraph();
      }
  
      private void setupGraph()
      {
          appComponent = DaggerAppComponent.builder()
                  .appModule(new AppModule(this))
                  .build();
      }
  
      @VisibleForTesting(otherwise = VisibleForTesting.NONE)
      public void setComponent(AppComponent component)
      {
          appComponent = component;
      }
  }
  </code></pre>
  
  <p>The sample runs fine. Am I missing something?</p>
  
  <p>I've uploaded the entire source code that I'm trying here: <a href="https://github.com/jbmlaird/DaggerMockRepository" rel="nofollow noreferrer">https://github.com/jbmlaird/DaggerMockRepository</a></p>