### Question:
VelocityScheduler implements Scheduler { @Override public TaskBuilder buildTask(Object plugin, Runnable runnable) { checkNotNull(plugin, "plugin"); checkNotNull(runnable, "runnable"); checkArgument(pluginManager.fromInstance(plugin).isPresent(), "plugin is not registered"); return new TaskBuilderImpl(plugin, runnable); } VelocityScheduler(PluginManager pluginManager); @Override TaskBuilder buildTask(Object plugin, Runnable runnable); boolean shutdown();  }### Answer:
@Test void buildTask() throws Exception { VelocityScheduler scheduler = new VelocityScheduler(new FakePluginManager()); CountDownLatch latch = new CountDownLatch(1); ScheduledTask task = scheduler.buildTask(FakePluginManager.PLUGIN_A, latch::countDown) .schedule(); latch.await(); assertEquals(TaskStatus.FINISHED, task.status()); }
@Test void cancelWorks() throws Exception { VelocityScheduler scheduler = new VelocityScheduler(new FakePluginManager()); AtomicInteger i = new AtomicInteger(3); ScheduledTask task = scheduler.buildTask(FakePluginManager.PLUGIN_A, i::decrementAndGet) .delay(100, TimeUnit.SECONDS) .schedule(); task.cancel(); Thread.sleep(200); assertEquals(3, i.get()); assertEquals(TaskStatus.CANCELLED, task.status()); }
@Test void repeatTaskWorks() throws Exception { VelocityScheduler scheduler = new VelocityScheduler(new FakePluginManager()); CountDownLatch latch = new CountDownLatch(3); ScheduledTask task = scheduler.buildTask(FakePluginManager.PLUGIN_A, latch::countDown) .delay(100, TimeUnit.MILLISECONDS) .repeat(100, TimeUnit.MILLISECONDS) .schedule(); latch.await(); task.cancel(); }