title: Match generics with Mockito
body: <p>I'm trying to mock the <code>restTemplate.exchange</code> method of Spring Rest.</p>
  
  <p>In the same test I have multiple calls which differ only by the return type.</p>
  
  <p>Here are the methods with the mocks I created</p>
  
  <p>First</p>
  
  <pre><code>// Original method
  restTemplate.exchange(UrlMap.SEARCH + '?' + searchDocsForm.toQueryParams(),
              HttpMethod.GET, null, new ParameterizedTypeReference&lt;SearchResultsDTO&lt;SolrDocumentDTO&gt;&gt;() {
              })
  // Mock
  when(restTemplate.exchange(any(String.class), any(HttpMethod.class), any(), Matchers.&lt;ParameterizedTypeReference&lt;SearchResultsDTO&lt;SolrDocumentDTO&gt;&gt;&gt;any())).thenReturn(
              new ResponseEntity&lt;&gt;(searchResultsDTO, HttpStatus.OK));
  </code></pre>
  
  <p>Second</p>
  
  <pre><code>// Original method
  restTemplate.exchange(UrlMap.ALL_DOCUS_TOPICS,
              HttpMethod.GET, null, new ParameterizedTypeReference&lt;List&lt;SelectItem&gt;&gt;() {
              }).getBody();
  // Mock
  when(restTemplate.exchange(any(String.class), any(HttpMethod.class), any(), Matchers.&lt;ParameterizedTypeReference&lt;List&lt;SelectItem&gt;&gt;&gt;any())).thenReturn(
              new ResponseEntity&lt;&gt;(selectItems, HttpStatus.OK));
  </code></pre>
  
  <p>The generic parameters of <code>ParameterizedTypeReference</code> are not considered by the mock, and the last defined mock wins over the former.</p>
  
  <p>Is there any way to make it work?</p>