title: Mockito/JMockit & Hamcrest matchers : How to verify Lists/Collections?
body: <p>This <a href="https://stackoverflow.com/q/20441594/827480">2013 post on SO</a> asked how to use Hamcrest matchers to verify lists/collections invocations in Mockito.  The accepted solution was to cast the Matcher to a (Collection).  </p>
  
  <p>I'm trying to do something similar, but running into a class cast error.  I am not sure if I am misusing Hamcrest matchers, or if this usage simply isn't supported by Mockito.  In my case, I'm trying to use a list of Matchers as my argument:</p>
  
  <pre><code>static class Collaborator
  {
     void doSomething(Iterable&lt;String&gt; values) {}
  }
  
  @Test
  public void usingMockito()
  {
     Collaborator mock = Mockito.mock(Collaborator.class);
     mock.doSomething(Arrays.asList("a", "b"));
  
     // legal cast
     Mockito.verify(mock).doSomething((Collection&lt;String&gt;)argThat(Matchers.contains("a", "b")));
     // legal cast
     Mockito.verify(mock).doSomething((Collection&lt;String&gt;)argThat(Matchers.contains(Matchers.equalTo("a"), Matchers.equalTo("b"))));
  
     // illegal cast!!! Cannot cast from Iterable&lt;capture#3-of ? extends List&lt;Matcher&lt;String&gt;&gt;&gt; to Collection&lt;String&gt;
     Mockito.verify(mock).doSomething((Collection&lt;String&gt;)argThat(Matchers.contains(Arrays.asList(Matchers.equalTo("a"), Matchers.equalTo("b")))));
  }
  </code></pre>
  
  <p>But I get the cast error:</p>
  
  <pre><code>Cannot cast from Iterable&lt;capture#3-of ? extends List&lt;Matcher&lt;String&gt;&gt;&gt; to Collection&lt;String&gt;
  </code></pre>
  
  <p>Am I doing something unsupported?</p>