@Test
public void testReschedule() throws InterruptedException {

    ScheduledExecutorService ses = 
        Executors.newSingleThreadScheduledExecutor();
    final Object tc = this;
    SingletonTask st1 = new SingletonTask(ses, new Runnable() {
        @Override
        public void run() {
            synchronized (tc) {
                ran += 1;
            }
            time = System.nanoTime();
        }
    });
    long start = System.nanoTime();
    st1.reschedule(20, TimeUnit.MILLISECONDS);
    Thread.sleep(5);
    assertFalse("Check that task hasn't run yet", ran > 0);
    st1.reschedule(20, TimeUnit.MILLISECONDS);
    Thread.sleep(5);
    assertFalse("Check that task hasn't run yet", ran > 0);
    st1.reschedule(20, TimeUnit.MILLISECONDS);
    Thread.sleep(5);
    assertFalse("Check that task hasn't run yet", ran > 0);
    st1.reschedule(20, TimeUnit.MILLISECONDS);
    Thread.sleep(5);
    assertFalse("Check that task hasn't run yet", ran > 0);
    st1.reschedule(20, TimeUnit.MILLISECONDS);
    Thread.sleep(5);
    assertFalse("Check that task hasn't run yet", ran > 0);
    st1.reschedule(20, TimeUnit.MILLISECONDS);
    Thread.sleep(5);
    assertFalse("Check that task hasn't run yet", ran > 0);
    st1.reschedule(20, TimeUnit.MILLISECONDS);
    Thread.sleep(5);
    assertFalse("Check that task hasn't run yet", ran > 0);
    st1.reschedule(20, TimeUnit.MILLISECONDS);
    Thread.sleep(5);
    assertFalse("Check that task hasn't run yet", ran > 0);
    
    ses.shutdown();
    ses.awaitTermination(5, TimeUnit.SECONDS);
    
    assertEquals("Check that task ran only once", 1, ran);
    assertTrue("Check that time passed appropriately: " + (time - start),
            (time - start) >= TimeUnit.NANOSECONDS.convert(55, TimeUnit.MILLISECONDS));
}