@Test
public void testConcurrentAddDelay2() 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;
            }
            try {
                Thread.sleep(50);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            synchronized (tc) {
                finished += 1;
                time = System.nanoTime();
            }
        }
    });
    st1.reschedule(5, TimeUnit.MILLISECONDS);
    Thread.sleep(20);
    assertEquals("Check that task started", 1, ran);
    assertEquals("Check that task not finished", 0, finished);
    st1.reschedule(25, TimeUnit.MILLISECONDS);
    assertTrue("Check task running state true", st1.context.taskRunning);
    assertTrue("Check task should run state true", st1.context.taskShouldRun);
    assertEquals("Check that task started", 1, ran);
    assertEquals("Check that task not finished", 0, finished);
    Thread.sleep(150);
    assertTrue("Check task running state false", !st1.context.taskRunning);
    assertTrue("Check task should run state false", !st1.context.taskShouldRun);
    assertEquals("Check that task ran exactly twice", 2, ran);
    assertEquals("Check that task finished exactly twice", 2, finished);
    ses.shutdown();
    ses.awaitTermination(5, TimeUnit.SECONDS);
}