title: Mocking Jersey Client ClientResponse with Mockito
body: <p>I am having some problems with mocking com.sun.jersey.api.client.ClientResponse but only when I am setting the .type(MediaType.MULTIPART_FORM_DATA_TYPE.</p>
  
  <p>I am stuck with jersey-client 1.18.</p>
  
  <p>Here is the code under test:</p>
  
  <pre><code> ClientResponse clientResponse = client.resource(url)
              .accept("application/json")
              .entity(multiPart)
              .type(MediaType.MULTIPART_FORM_DATA_TYPE)
              .post(ClientResponse.class);
  </code></pre>
  
  <p>Here is the mocking for the test:</p>
  
  <pre><code> when(clientResponse.getEntity(String.class)).thenReturn(body);
   when(builder.post(eq(ClientResponse.class))).thenReturn(clientResponse);
   when(builder.type(MediaType.MULTIPART_FORM_DATA_TYPE)).thenReturn(builder);
   when(webResource.accept(anyString())).thenReturn(builder);
   when(client.resource(anyString())).thenReturn(webResource);;
  </code></pre>
  
  <p>The error I receive is a NullPointerException in the Code under Test at the line:</p>
  
  <pre><code> .type(MediaType.MULTIPART_FORM_DATA_TYPE)
  </code></pre>
  
  <p>Anyone know how to mock the Client.resource().type()?</p>