@Override
  public ScheduledFuture<@Nullable ?> schedule(Runnable command, long delay, TimeUnit unit) {
    if (command == null || unit == null) {
      throw new NullPointerException();
    }
    ScheduledFutureTask<Void> task =
        new ScheduledFutureTask<>(command, null, triggerTime(delay, unit));
    runNowOrScheduleInTheFuture(task);
    return task;
  }
@Test
  public void testSchedule() throws Exception {
    List<AtomicInteger> callCounts = new ArrayList<>();
    List<ScheduledFutureTask<?>> futures = new ArrayList<>();

    FastNanoClockAndSleeper fastNanoClockAndSleeper = new FastNanoClockAndSleeper();
    UnboundedScheduledExecutorService executorService =
        new UnboundedScheduledExecutorService(fastNanoClockAndSleeper);

    callCounts.add(new AtomicInteger());
    futures.add(
        (ScheduledFutureTask<?>)
            executorService.schedule(
                (Runnable) callCounts.get(callCounts.size() - 1)::incrementAndGet,
                100,
                MILLISECONDS));
    callCounts.add(new AtomicInteger());
    futures.add(
        (ScheduledFutureTask<?>)
            executorService.schedule(
                callCounts.get(callCounts.size() - 1)::incrementAndGet, 100, MILLISECONDS));

    // No tasks should have been picked up
    wakeUpAndCheckTasks(executorService);
    for (int i = 0; i < callCounts.size(); ++i) {
      assertEquals(0, callCounts.get(i).get());
    }

    // No tasks should have been picked up even if the time advances 99 seconds
    fastNanoClockAndSleeper.sleep(99);
    wakeUpAndCheckTasks(executorService);
    for (int i = 0; i < callCounts.size(); ++i) {
      assertEquals(0, callCounts.get(i).get());
    }

    // All tasks should wake up and pick-up tasks
    fastNanoClockAndSleeper.sleep(1);
    wakeUpAndCheckTasks(executorService);

    assertNull(futures.get(0).get());
    assertEquals(1, futures.get(1).get());

    for (int i = 0; i < callCounts.size(); ++i) {
      assertFalse(futures.get(i).isPeriodic());
      assertEquals(1, callCounts.get(i).get());
    }

    assertThat(executorService.shutdownNow(), empty());
  }