title: Strict stubbing argument mismatch when using anyMap() vs (Object)any()
body: <p>I am trying to understand why Mockito is acting so weird when trying to mock the Spring <code>RestTemplate</code>.</p>
  <p>I have the following code:</p>
  <pre><code>when(restTemplate.exchange(any(String.class),
                  any(HttpMethod.class),
                  any(HttpEntity.class),
                  eq(ServiceResponse.class),
                  anyMap()))
                  .thenReturn(ResponseEntity.ok(expectedResponse));
  </code></pre>
  <p>This code gives the following error:</p>
  <pre><code>Strict stubbing argument mismatch. Please check:
   - this invocation of 'exchange' method:
      restTemplate.exchange(
      &quot;baseUrlPath&quot;,
      GET,
      &lt;[ApiKey:&quot;apiKey&quot;]&gt;,
      class com.model.baz.ServiceResponse,
      {&quot;param1&quot; = &quot;foo&quot;, &quot;param2&quot; = &quot;bar&quot;}
  );
      -&gt; at com.client.Client.getServiceResponse(Client.java:65)
   - has following stubbing(s) with different arguments:
      1. restTemplate.exchange(
      null,
      null,
      null,
      null,
      {}
  );
  </code></pre>
  <p>But when I replace <code>anyMap</code> with <code>(Object)any()</code> the code magically works.</p>
  <p>My worry is that Mockito is not stubbing the correct method when I am using <code>(Object)any()</code> since <code>RestTemplate</code> has two overloaded methods:</p>
  <pre><code>public &lt;T&gt; ResponseEntity&lt;T&gt; exchange(String url, HttpMethod method,
              @Nullable HttpEntity&lt;?&gt; requestEntity, Class&lt;T&gt; responseType, Object... uriVariables)
  </code></pre>
  <p>and</p>
  <pre><code>public &lt;T&gt; ResponseEntity&lt;T&gt; exchange(String url, HttpMethod method,
              @Nullable HttpEntity&lt;?&gt; requestEntity, Class&lt;T&gt; responseType, Map&lt;String, ?&gt; uriVariables)
  </code></pre>
  <p>I think when I am using <code>(Object)any()</code> it goes for the 1st method, when in reality I need the second method to be stubbed.</p>
  <p><strong>Also why does <code>any()</code> not work ? Why is the <code>Object</code> cast required ?</strong></p>
  <p>Thanks.</p>