title: Mockito and Guice : mocking a @Provides method
body: <p>I have a module in my class called MainModule. It has various bindings in it, one of which is a binding to my custom service interface called HttpClientPool</p>
  
  <pre><code>public class MainModule extends AbstractVertxModule{
          binder.bind(HttpClientPool.class).to(HttpClientPoolImpl.class).in(Singleton.class);
          // other bindings
  } 
  
  @Provides @Singleton
      public TokenClient tokenClient(HttpClientPool clientPool){
          return new TokenClient(clientPool);
  }
  </code></pre>
  
  <p>The module is also a provider of an object called tokenClient, as seen above.</p>
  
  <p>The tokenClient is being injected somewhere else in a different class and a few methods are being invoked on this object.</p>
  
  <p>In my unit tests, I'm intending to use Mockito to get a mocked tokenClient object. That means, I would like MainModule to provide a mocked object, instead of a real one. I have tried using a testMainModule that looks like this:</p>
  
  <pre><code>public class testMainModile implements Module{
      private TokenClient tokenClient;
  
      public TokenModule(TokenClient client) {
          this.tokenClient= client;
      }
  
      @Override
      public void configure(Binder binder) {
          binder.bind(TokenClient.class).toInstance(tokenClient);
      }
  }
  </code></pre>
  
  <p>An excerpt from my unit tests:</p>
  
  <pre><code>@Mock
  private TokenClient tokenClient;
  // Stuff between
  Injector messagingInjector = Guice.createInjector(new TestMainModule(tokenClient));
          mainModule = messagingInjector.getInstance(MainModule.class);
  </code></pre>
  
  <p>Somehow, all I get is a real object from the mainModule object. Am I missing something?</p>