title: How to unit test callback logic?
body: <p>More complete question is, given a dependency that expects a callback as a parameter, how do I write a unit test that covers the callback logic <em>and</em> still manage to mock up the dependency?</p>
  
  <pre><code>public class DoStuff {
      public void runThis(Runnable callback) {
          // call callback
      }
  }
  
  public class ClassUnderTest {
      private DoStuff stuffToDo;
  
      public void methodUnderTest() {
          this.stuffToDo.runThis(/*a runnable with some logic*/)
      }
  }
  </code></pre>
  
  <p>In the example above, I would mock <code>stuffToDo</code> since I should verify calls and mock outputs of method calls. However, mocking <code>runThis</code> results in the callback logic not being tested. Furthermore, callback logic seems like it should be private so I wouldn't expect to test it directly; perhaps that is a misconception on my part.</p>
  
  <p>Since callbacks are used rather extensivly, I would expect there to be a common method for testing them but I haven't found it.</p>