title: capturing previous values to verify mock object
body: <p>In mockito, is it possible to capture the previous value set to a field of an object passed to a mock object's method for example the method under test performs this</p>
  
  <pre><code>    public void methodUnderTest(){
      Person person = new Person();
      person.setAge(5);
      someObject.setPerson(person);
  
       ...
  
      person.setAge(6); 
      someObject.setPerson(person);
      }
  </code></pre>
  
  <p>What I wanted to know is if I mock someObject, will I be able to verify that someObject performed setPerson to a single object "person" twice but the object had different value for age when setPerson occurred? I tried using ArgumentCaptor but since I passed the same object, I was just able to get the last age.</p>
  
  <pre><code>    ArgumentCaptor&lt;Integer&gt; arg = ArgumentCaptor.forClass(Integer.class);
      verify(mockObject).setPerson(arg.capture());
      List&lt;Integer&gt; captureList = arg.getAllValues();
      captureList.get(0).getAge(); // returns 6
      captureList.get(1).getAge(); // returns 6
  </code></pre>
  
  <p>I also tried doing</p>
  
  <pre><code>    InOrder in = inOrder(mockObject);
      in.verify(mockObject).setPerson(arg.capture());
      assertEquals(5, arg.getValue().getAge()); //fails
  </code></pre>