title: Mockito mock object with list argument's contents
body: <p>I've faced this situation pretty often and don't know how to resolve it using Mockito's default methods such as (any, anyList, eq)</p>
  
  <p>For example I have an object where I want to mock a method expecting a list which contains other mocked objects. Let me explain:</p>
  
  <pre><code>public class MyMapper {
     public List&lt;DataObjects&gt; convertList(List&lt;String&gt; rawContents) {
        rawContents.stream().map(r -&gt; convertObject(r))
        .collect(Collectors.toList());
     }
  
     public DataObject convertObject(String rawContent) {
         return new DataObject(rawContent);
     }
  } 
  
  public class MyWorkerClass {
       public boolean start(List&lt;String&gt; rawContents) {
             List&lt;DataObject&gt; objects = new MyMapper().convertList(rawContents);
             return publish(objects);
       }
  
       public boolean result publish(List&lt;DataObject&gt; objects) {
             ../// some logic
       }
  }
  </code></pre>
  
  <p>Now what I want to assert is something like. <strong>Note: Please assume the right mocks are returned when new() is called [Using some PowerMockito]</strong></p>
  
  <pre><code>@Test
  public void test() {
     String content = "content";
     DataObject mock1 = Mockito.mock(DataObject.class);
     MyMapper mapperMock = Mockito.mock(MyMapper.class);
     MyWorkerClass worker = new MyWorkerClass();
  
     Mockito.when(mapperMock.convertObject(content)).thenReturn(mock1);
  
     Mockito.when(worker.publish(eq(Arrays.asList(mock1)).thenReturn(true);
  
     boolean result = worker.start(Arrays.asList(content));
     Assert.assertTrue(result);
  }
  </code></pre>
  
  <p>The problem with the code above is in the line</p>
  
  <pre><code>  Mockito.when(worker.publish(eq(Arrays.asList(mock1)).thenReturn(true);
  </code></pre>
  
  <p>This will try to match the list object instead of the list contents, in other words, even when I have to lists A: [mock1] and B: [mock1], A is not equal to B and ultimately the stubbing fails.</p>
  
  <p>What I need is some sort of matcher similar to hamcrest's <code>contain</code> matcher. Something like:</p>
  
  <pre><code>  Mockito.when(worker.publish(contains(mock1)).thenReturn(true));
  </code></pre>
  
  <p>Is there anyway I can achieve this? Keep in mind the code above is just an example to grasp the problem, the real situation is a little bit more complex and I can only mock individual objects, not the list itself</p>
  
  <p>Thanks</p>