title: How to mock feign.Client.Default with Mockito
body: <p>I'm writing a <code>Dropwizard</code> application and using <code>Feign</code> for building client calls to outside services. I have custom encoders and decoders I'm registering with the <code>feign.Builder</code> like so:</p>
  
  <pre class="lang-java prettyprint-override"><code>    this.feignBuilder = Feign.builder()
              .contract(new JAXRSContract()) // we want JAX-RS annotations
              .encoder(new JacksonEncoder()) // same as what dropwizard is using
              .decoder(new CustomDecoder())
              .errorDecoder(new CustomErrorDecoder())
              .requestInterceptor(new AuthKeyInterceptor(config.getInterceptor()));
  </code></pre>
  
  <p>I'm writing unit tests for the <code>feign</code> client calls so I can watch how the feign machinery deals with my encoder/decoder overrides and bubbles on exceptions. I'm not interested in writing integration tests with a fake server right now (this is the most common type of test i see people writing for this situation).</p>
  
  <p>This should be straight forward. I want to mock the point at which <code>feign</code> makes the request and have it return my fake response. That means I should mock the call to <code>feign.Client.Default.execute</code> so it returns my fake response when it makes the request a <a href="https://github.com/Netflix/feign/blob/129f9a4219589f60b95e7c7d552e1ce93ef36e32/core/src/main/java/feign/SynchronousMethodHandler.java#L92" rel="nofollow">this call site</a>. An example of what that mock looks like:</p>
  
  <pre class="lang-java prettyprint-override"><code>String responseMessage = "{\"error\":\"bad\",\"desc\":\"blah\"}";
  feign.Response feignResponse = FeignFakeResponseHelper.createFakeResponse(404,"Bad Request",responseMessage);
  Client.Default mockFeignClient = mock(Client.Default.class);
  try {
       when(mockFeignClient.execute(any(feign.Request.class),any(Request.Options.class))).thenReturn(feignResponse);
  } catch (IOException e) {
       assertThat(true).isFalse(); // fail nicely
  }
  </code></pre>
  
  <p>No luck. The <code>Cleint.Default</code> class isn't mocked when I reach the <a href="https://github.com/Netflix/feign/blob/129f9a4219589f60b95e7c7d552e1ce93ef36e32/core/src/main/java/feign/SynchronousMethodHandler.java#L92" rel="nofollow">call site</a> for the request in the code. What am I doing wrong?</p>