title: Best practices for verifying recursive method calls with Mockito
body: <p>Consider this example class:</p>
  
  <pre><code>public class Processor {
    private final Dependency dependency;
  
    public Processor(Dependency dependency) {
      this.dependency = dependency;
    }
  
    public void processUsers(List&lt;Integer&gt; userIds, int attempt) {
      if (attempt == 0) {
        //log initial processing
      } else if (attempt &gt; 0 &amp;&amp; attempt &lt; 5) {
        //log retry processing
      } else {
        //log processing limit exceeded
        return;
      }
      List&lt;Integer&gt; failedIds = new ArrayList&lt;Integer&gt;();
      for (Integer userId : userIds) {
        try {
          processUser(userId);
        } catch (Exception ex) {
          //logging
          failedIds.add(userId);
        }
      }
      if (failedIds.isEmpty()) {
        //log ok
      } else {
        processUsers(failedIds, attempt + 1);
      }
    }
  
    public void processUser(Integer userId) throws Exception{
      //dependency can throw exception
      dependency.call();
    }
  }
  </code></pre>
  
  <p>I would like to verify that method <code>processUsers</code> calls itself when exception is thrown.
  Here is my testy test:</p>
  
  <pre><code>public class ProcessorTest {
    @Test
    public void processShouldCallItselfWithFailedSublistWhenProcessingFails(){
      Dependency dependency = mock(Dependency.class);
      when(dependency.call()).thenThrow(Exception.class);
      Processor processor = new Processor(dependency);
      processor.processUsers(Arrays.asList(new Integer[]{1,2,3}), 0);
      //need to verify processor will call #processUsers recursively
      //because the dependency thrown Exception, how?
    }
  }
  </code></pre>
  
  <p>What are best practices for verifying that method calls itself recursively under certain circumstances?</p>
  
  <p>I'm using TestNG + Mockito and this verbose language called <code>JAVA</code></p>