title: Mockito and Hamcrest: how to verify invocation of Collection argument?
body: <p>I'm running into a generics problem with Mockito and Hamcrest.</p>
  
  <p>Please assume the following interface:</p>
  
  <pre><code>public interface Service {
      void perform(Collection&lt;String&gt; elements);
  }
  </code></pre>
  
  <p>And the following test snippet:</p>
  
  <pre><code>Service service = mock(Service.class);
  
  // ... perform business logic
  
  verify(service).perform(Matchers.argThat(contains("a", "b")));
  </code></pre>
  
  <p>So I want to verify that my business logic actually called the service with a collection that contains "a" and "b" in that order.</p>
  
  <p>However, the return type of <code>contains(...)</code> is <code>Matcher&lt;Iterable&lt;? extends E&gt;&gt;</code>, so <code>Matchers.argThat(...)</code> returns <code>Iterable&lt;String&gt;</code> in my case, which naturally does not apply to the required <code>Collection&lt;String&gt;</code>.</p>
  
  <p>I know that I could use an argument captor as proposed in <a href="https://stackoverflow.com/questions/17174192/hamcrest-hasitem-and-mockito-verify-inconsistency">Hamcrest hasItem and Mockito verify inconsistency</a>, but I would very much like not to.</p>
  
  <p>Any suggestions!
  Thanks!</p>