title: How to capture same object multiple times in Mockito argument captor
body: <p>I was writing a Junit to test a scenario where an object changes its variables and saves it into the database 2 times. The <code>argumentCaptor</code> is invoked in save operation. The <code>getAllValues()</code> is returning two records. But both values are referenced to the same last capture record. </p>
  
  <p>ImplimentationClass.java</p>
  
  <pre class="lang-java prettyprint-override"><code> ...
  
  myObj.setVariable(oneValue);
  saveMyObj(myObj);
  myObj.setVariable(otherValue);
  saveMyObj(myObj);
  
  ...
  
  saveMyObj(MyObject myObj){
  repository.save(myObj);
  }
  
  </code></pre>
  
  <p>ImplimentationClassTest.java</p>
  
  <pre><code>
  private ImplimentationClass underTest ;
  
  @Mock
  private Repository mockRepository;
  
  @Before
  public void setup(){
    initMocks(this);
    underTest = new ImplimentationClassTest();
  }
  
  @Test
  public void test(){
  ArgumentCaptor&lt;MyObject&gt; captor = ArgumentCaptor.forClass(MyObject.class);
  MyObject obj = new MyObject(value);
  underTest.implementedMethod(obj);
  verify(mockRepository, times(2)).save(captor.capture());
  assertEquals(oneValue, captor.getAllValues().get(0).getVariable()); //failing here -getting otherValue
  assertEquals(otherValue, captor.getAllValues().get(1).getVariable());
  
  }
  </code></pre>
  
  <p>Any idea how to capture same object multiple times?</p>