title: Mockito verify that method is called with correct argument using regex
body: <h1>Description</h1>
  
  <p>I am trying to test the following class:</p>
  
  <pre><code>Class UserSynchronizer(){
     private static org.apache.log4j.Logger log = ... ;
  
     public Sync(candidate) { 
       ...
       if (candidate.inValidForSync()) {
         log.debug("Candidate #" + candidate.getId() + ": Not syncing");
       }
       else {
         log.debug("Syncing");
       }
     }
  
   }
  </code></pre>
  
  <p>I want to see if mockito can detect what arguments <code>log.debug</code> was called with and then I want to see if I can do some kind of regex check on it. In other words, I want to:</p>
  
  <ul>
  <li>capture the arguments provided to the log object (which I am mocking in my test atm)</li>
  <li>check (using regex) if it matches a pattern like "Candidate #\d+: Not syncing" for the cases where my mock candidate object is returning false</li>
  </ul>
  
  <h1>Test code</h1>
  
  <p>The code below is what I have as a starting point:</p>
  
  <pre><code>public void verifySyncDoesntSyncWhenInvalid(){
    //Setup candidate mock
    Candidate invalidSyncCandidateMock = mock(Candidate.class);
    when(invalidSyncCandidateMock.inValidForSync()).thenReturn(true);
  
    //Setup log mock
    UserSynchronizer userSynchronizer = ...;
    Field logField = userSynchronizer.getClass().getDeclaredField("log");
    logField.setAccessible(true);
    logField.set(userSynchronizer, logMock);
  
    //Call sync
    userSynchronizer.sync(invalidSyncCandidateMock);
  
    //Verify that debug was called with ("Candidate #\d+: Not syncing")
    ???
  }
  </code></pre>
  
  <h1>Problem</h1>
  
  <p>The problem is that <code>log.debug</code> is called multiple times. I want to capture the arguments that are provided to <code>log.debug</code> and ensure that when it is called with the candidate that is invalid for sync, then the logger object correctly logs that the candidate was not synced.</p>
  
  <p>Edit: If this has been asked before, I apologize. I kindly ask that you post a link to the related question :)</p>