title: Testing timer using JUnit
body: <p>I'm trying to test my Timer and I can't seem to be able to execute my task more than 1 time...</p>
  
  <p>how can I test this class so it can run multiple times?</p>
  
  <p>here's my code </p>
  
  <pre><code>package rpm.mode.offline;
  
  import java.util.Timer;
  import java.util.TimerTask;
  import org.apache.log4j.Logger;
  import rpm.logging.LOG;
  import rpm.patient.properties.OptionsProperties;
  
  public class ResendController {
  
  private static final Logger LOG = new LOG().getLogger();
  
  private static ResendController instance = new ResendController();
  private static OfflineDataLayer staticofflineDataLayer;
  private int nbRetriesAllowed = 0;
  private int nbActualRetries = 0;
  private int retryTimeDelay = 0;
  Timer timer;
  
  public static ResendController getInstance(OfflineDataLayer offlineDataLayer) {
      staticofflineDataLayer = offlineDataLayer;
      return instance;
  }
  
  private ResendController() {
      nbRetriesAllowed = Integer.parseInt(OptionsProperties.getProperty(OptionsProperties.RESEND_NUMBER_RETRIES));
      retryTimeDelay = Integer.parseInt(OptionsProperties.getProperty(OptionsProperties.RESEND_DELAY_IN_MINUTES));
  }
  
  public void sendAnswers() {
      if (timer == null) {
          timer = new Timer();
          timer.schedule(new ResendTask(), 1);
          System.out.println("ResendTask task created...");
      }
  }
  
  /*
   * The Task that sends the answers of the patient.
   */
  class ResendTask extends TimerTask {
  
      @Override
      public void run() {
          System.out.println("ResendTask run() is called....");
        }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and my Junit:</p>
  
  <pre><code>package rpm.mode.offline;
  
  import org.junit.Test;
  
  public class TestResendController {
  
  @Test
  public void testResend() throws InterruptedException {
      System.out.println("Java timer is about to start");
  
      OfflineDataLayer datalayer = null;
      ResendController controller = ResendController.getInstance(datalayer);
      controller.sendAnswers();
      Thread.sleep(4000);
      System.out.print("Pass 1...");
      Thread.sleep(4000);
      System.out.print("Pass 2...");
      Thread.sleep(4000);
      System.out.print("Pass 3...");
      Thread.sleep(4000);
      System.out.print("Pass 4...");
      Thread.sleep(4000);
      System.out.print("Pass 5...");
      Thread.sleep(4000);
      System.out.print("Pass 6...");
  
  }
  }
  </code></pre>
  
  <p>Output:
  ResendTask task created...
  ResendTask run() is called....
  Pass 1...Pass 2...Pass 3...Pass 4...Pass 5...Pass 6...</p>