### Question:
DefaultSchedulerService implements SchedulerService { @Override public void terminate(final String beanName) { if (this.applicationContext.containsBean(beanName)) { final Scheduler scheduler = this.applicationContext.getBean(beanName, Scheduler.class); if (scheduler.getSchedulerStatus().equals(SchedulerStatus.STOPPED)) { log.info("Scheduler: " + beanName + " already terminated"); } else { scheduler.terminate(); } } else { throw new SpringBatchLightminConfigurationException("Could not terminate bean with name: " + beanName); } } DefaultSchedulerService(final BeanRegistrar beanRegistrar,
                                   final JobRepository jobRepository,
                                   final JobRegistry jobRegistry); @Autowired void setApplicationContext(final ApplicationContext applicationContext); @Override String registerSchedulerForJob(final JobConfiguration jobConfiguration); @Override void unregisterSchedulerForJob(final String beanName); @Override void refreshSchedulerForJob(final JobConfiguration jobConfiguration); @Override void schedule(final String beanName, final Boolean forceScheduling); @Override void terminate(final String beanName); @Override SchedulerStatus getSchedulerStatus(final String beanName); @Override void afterPropertiesSet(); @Override JobLauncher createLobLauncher(final TaskExecutorType taskExecutorType, final JobRepository jobRepository);  }### Answer:
@Test public void terminateTest() { final String beanName = "schedulerBean"; when(this.applicationContext.containsBean(beanName)).thenReturn(Boolean.TRUE); when(this.applicationContext.getBean(beanName, Scheduler.class)).thenReturn(this.scheduler); when(this.scheduler.getSchedulerStatus()).thenReturn(SchedulerStatus.RUNNING); this.schedulerService.terminate(beanName); verify(this.scheduler, times(1)).terminate(); }
@Test(expected = SpringBatchLightminConfigurationException.class) public void terminateUnknownTest() { final String beanName = "schedulerBean"; when(this.applicationContext.containsBean(beanName)).thenReturn(Boolean.FALSE); this.schedulerService.terminate(beanName); }