### Question:
ReportPublisher implements Runnable { public void init(StateContext stateContext, ScheduledExecutorService executorService) { this.context = stateContext; this.executor = executorService; this.executor.schedule(this, getReportFrequency(), TimeUnit.MILLISECONDS); }  void init(StateContext stateContext,
                   ScheduledExecutorService executorService); void setConf(ConfigurationSource conf); ConfigurationSource getConf(); @Override void run();  }### Answer:
@Test public void testReportPublisherInit() { ReportPublisher publisher = new DummyReportPublisher(0); StateContext dummyContext = Mockito.mock(StateContext.class); ScheduledExecutorService dummyExecutorService = Mockito.mock( ScheduledExecutorService.class); publisher.init(dummyContext, dummyExecutorService); verify(dummyExecutorService, times(1)).schedule(publisher, 0, TimeUnit.MILLISECONDS); }
@Test public void testScheduledReport() throws InterruptedException { ReportPublisher publisher = new DummyReportPublisher(100); StateContext dummyContext = Mockito.mock(StateContext.class); ScheduledExecutorService executorService = HadoopExecutors .newScheduledThreadPool(1, new ThreadFactoryBuilder().setDaemon(true) .setNameFormat("Unit test ReportManager Thread - %d").build()); publisher.init(dummyContext, executorService); Thread.sleep(150); Assert.assertEquals(1, ((DummyReportPublisher) publisher).getReportCount); Thread.sleep(100); Assert.assertEquals(2, ((DummyReportPublisher) publisher).getReportCount); executorService.shutdown(); }