title: Getting a TimerTask to run when using JUnit
body: <p>I have a function that looks like this:</p>
  
  <pre><code>private Timer timer = new Timer();
  
  private void doSomething() {
      timer.schedule(new TimerTask() {
          public void run() {
              doSomethingElse();
          }
      },
      (1000));
  }
  </code></pre>
  
  <p>I'm trying to write JUnit tests for my code, and they are not behaving as expected when testing this code in particular. By using EclEmma, I'm able to see that my tests never touched the <code>doSomethingElse()</code> function.</p>
  
  <p>How do I write tests in JUnit that will wait long enough for the <code>TimerTask</code> to finish before continuing with the test?</p>