title: Mockito to test void methods
body: <p>I have following code I want to test:</p>
  
  <pre><code>public class MessageService {
      private MessageDAO dao;
  
      public void acceptFromOffice(Message message) {
          message.setStatus(0);
          dao.makePersistent(message);
  
          message.setStatus(1);
          dao.makePersistent(message);
  
      }
      public void setDao (MessageDAO mD) { this.dao = mD; }
  }
  
  public class Message {
      private int status;
      public int getStatus () { return status; }
      public void setStatus (int s) { this.status = s; }
  
      public boolean equals (Object o) { return status == ((Message) o).status; }
  
      public int hashCode () { return status; }
  }
  </code></pre>
  
  <p>I need to verify, that method acceptFromOffice really sets status to 0, than persist message, then chage its status to 1, and then persist it again.</p>
  
  <p>With Mockito, I have tried to do following:</p>
  
  <pre><code>@Test
      public void testAcceptFromOffice () throws Exception {
  
          MessageDAO messageDAO = mock(MessageDAO.class);
  
          MessageService messageService = new MessageService();
          messageService.setDao(messageDAO);
  
          final Message message = spy(new Message());
          messageService.acceptFromOffice(message);
  
          verify(messageDAO).makePersistent(argThat(new BaseMatcher&lt;Message&gt;() {
              public boolean matches (Object item) {
                  return ((Message) item).getStatus() == 0;
              }
  
              public void describeTo (Description description) { }
          }));
  
          verify(messageDAO).makePersistent(argThat(new BaseMatcher&lt;Message&gt;() {
              public boolean matches (Object item) {
                  return ((Message) item).getStatus() == 1;
              }
  
              public void describeTo (Description description) { }
          }));
  
      }
  </code></pre>
  
  <p>I actually expect here that verification will verify calling twice of makePersistent method with a different Message object's state. But it fails saying that </p>
  
  <blockquote>
    <p>Argument(s) are different!</p>
  </blockquote>
  
  <p>Any clues?</p>