title: JUnit/Mockito verifying `any(HttpPut.class)` however passes when other instances used too
body: <p>I have a service class that calls a REST API to get, create, update and delete subscribers. The Uri remains the same, but the HTTP method changes as you'd expect. I want to test the correct method is given. Below is an example of the updateSubscriber and its test.</p>
  
  <pre><code>public class MyService {
  
      HttpClient httpClient;
  
      public MyService(HttpClient httpClient) {
          this.httpClient = httpClient;
      }
  
      //...
  
      public int updateSubscriber(Subscriber subscriber) throws ... {
  
          // PUT is the correct method for this request 
          HttpResponse response = httpClient.execute( new HttpPut( "https://example.org/api/subscribers" ) );
  
          //...
      }
  
      //...
  </code></pre>
  
  <p>Here is my test with JUnit and Mockito:</p>
  
  <pre><code>@RunWith(MockitoJUnitRunner.class)
  public class MyServiceTest 
  {
  
      @Mock
      private HttpClient mockHttpClient;
  
      @Mock 
      private HttpResponse mockResponse;
  
      @Mock 
      private StatusLine mockStatusline;
  
      @Mock 
      private HttpEntity mockEntity;
  
      // test subject
      private MyService myService;
  
      @Before
      public void setup() {
  
          // // this will just ensure http* objects are returning our mocked instances so we can manipulate them..
          // when(mockHttpClient.execute(any(HttpGet.class))).thenReturn(mockResponse);
          // when(mockHttpClient.execute(any(HttpPost.class))).thenReturn(mockResponse);
          // when(mockHttpClient.execute(any(HttpPut.class))).thenReturn(mockResponse);
          // when(mockHttpClient.execute(any(HttpDelete.class))).thenReturn(mockResponse);
  
          // when(mockResponse.getStatusLine()).thenReturn(mockStatusline);
          // when(mockStatusline.getStatusCode()).thenReturn(HttpStatus.SC_OK);
  
          myService = new MyService(mockHttpClient);
      }
  
      @Test
      public void testUpdateSubscriber() throws ...
      {   
  
          when(mockHttpClient.execute(any(HttpPut.class))).thenReturn(mockResponse);
  
          when(mockResponse.getStatusLine()).thenReturn(mockStatusline);
          when(mockStatusline.getStatusCode()).thenReturn(HttpStatus.SC_OK);
  
          String responseString = "...";
  
          // this is consumed by a static method which we cannot mock, so we must deal with an actual entity instance 
          BasicHttpEntity entity = new BasicHttpEntity();
          entity.setContent(new ByteArrayInputStream(responseString.getBytes()));
          when(mockResponse.getEntity()).thenReturn(entity);  
  
          // create a test case Subscriber instance 
          Subscriber subscriber = new Subscriber();
  
          int statusCode = myService.updateSubscriber(subscriber);
  
          assertEquals(HttpStatus.SC_OK, statusCode);
  
          // just confirm that an HTTP request was made 
          // TODO this isn't working, still passes when wrong Http* method used 
          verify(mockHttpClient, times(1)).execute(any(HttpPut.class));
      }
  
      //...
  </code></pre>
  
  <p>However, when I (wrongfully) have the another Http* method instance, it still passes:</p>
  
  <pre><code>// this is wrong, and should fail, but passed :(
  HttpResponse response = httpClient.execute( new HttpGet( "https://example.org/api/subscribers" ) ); 
  </code></pre>
  
  <p>I'd really like to be able to test this as the action performed could be wrong if the method is mistaken. This test is to ensure that the PUT method was correctly used with the HTTP request for updateSubscriber. Any ideas?</p>