title: Mockito, argThat, and hasEntry
body: <blockquote>
    <p>tl;dr: These tests don't compile because the type parameters don't match. What changes should I make to make them compile and run
    correctly?</p>
    
    <p><a href="https://github.com/wesleym/matchertest" rel="noreferrer">https://github.com/wesleym/matchertest</a></p>
  </blockquote>
  
  <p>I have some non-test code that calls into a service. It calls the service's activate method with a map parameter.</p>
  
  <pre><code>public class Foo {
    private final Service service;
  
    public Foo(Service service) {
      this.service = service;
    }
  
    public void bar() {
      Map&lt;String, ?&gt; params = getParams();
      service.activate(params);
    }
  
    private Map&lt;String, ?&gt; getParams() {
      // something interesting goes here
    }
  }
  </code></pre>
  
  <p>Some code I'm trying to test has a dependency on a service like this one:</p>
  
  <pre><code>public interface Service {
    public void activate(Map&lt;String, ?&gt; params);
  }
  </code></pre>
  
  <p>I'd like to test this code by mocking the service with Mockito and verifying that activate was called with a reasonable map. The following code works:</p>
  
  <pre><code>@Test
  public void testExactMap() {
    Service mockService = mock(Service.class);
    Foo foo = new Foo(mockService);
  
    foo.bar();
  
    Map&lt;String, String&gt; expectedParams = new HashMap&lt;&gt;();
    expectedParams.put("paramName", "paramValue");
    verify(service).activate(expectedParams);
  }
  </code></pre>
  
  <p>However, I'd like to just test that the map contains one particular entry. The Hamcrest <a href="http://hamcrest.org/JavaHamcrest/javadoc/2.0.0.0/" rel="noreferrer">hasEntry matcher</a> seems perfect for this use case:</p>
  
  <pre><code>@Test
  public void testHasEntry() {
      Service mockService = mock(Service.class);
      Foo foo = new Foo(mockService);
  
      foo.bar();
  
      verify(mockService).activate(argThat(hasEntry("paramName", "paramValue")));
  }
  </code></pre>
  
  <p>When I try this, I get the following error in IntelliJ IDEA:</p>
  
  <pre><code>Error:(31, 45) java: incompatible types: inference variable T has incompatible bounds
      equality constraints: java.util.Map&lt;? extends java.lang.String,? extends java.lang.String&gt;
      upper bounds: java.util.Map&lt;java.lang.String,?&gt;,java.lang.Object
  </code></pre>
  
  <p>The problem here is that I need a Mockito matcher of <code>Map&lt;String, ?&gt;</code>, but hasEntry gives me a matcher of <code>Map&lt;? extends String, ? extends String&gt;</code>. Even with explicit type parameters, I can't figure out what to do to reconcile the "? extends" part of the type parameter. What should I do to resolve this error? Is there a specific cast or explicit type parameter I should use?</p>
  
  <p><em>I understand that I can use ArgumentCaptor for this.</em> Is that really the only way to do this? Is this possible at all with Hamcrest matchers?</p>