StatisticsService { public void startProcessCountJob() { int processCountIntervalSeconds = configService.getProcessCountIntervalSeconds(); if (processCountIntervalSeconds > 0) { scheduledExecutorService.scheduleAtFixedRate(new ProcessCountJob(coordinatorRegistryCenter, jobConfiguration), processCountIntervalSeconds, processCountIntervalSeconds, TimeUnit.SECONDS); } } StatisticsService(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration); void startProcessCountJob(); void stopProcessCountJob();  }
@Test public void assertStartProcessCountJobWhenNegativeProcessCountIntervalSeconds() { when(configService.getProcessCountIntervalSeconds()).thenReturn(-1); statisticsService.startProcessCountJob(); verify(configService).getProcessCountIntervalSeconds(); verify(scheduledExecutorService, times(0)).scheduleAtFixedRate(Matchers.<ProcessCountJob>any(), eq(-1L), eq(-1L), eq(TimeUnit.SECONDS)); }
@Test public void assertStartProcessCountJobWhenPositiveProcessCountIntervalSeconds() { when(configService.getProcessCountIntervalSeconds()).thenReturn(10); statisticsService.startProcessCountJob(); verify(configService).getProcessCountIntervalSeconds(); verify(scheduledExecutorService).scheduleAtFixedRate(Matchers.<ProcessCountJob>any(), eq(10L), eq(10L), eq(TimeUnit.SECONDS)); }