JobScheduleController { public void shutdown() { schedulerFacade.releaseJobResource(); try { if (!scheduler.isShutdown()) { scheduler.shutdown(); } } catch (final SchedulerException ex) { throw new JobException(ex); } }  void scheduleJob(final String cronExpression); void rescheduleJob(final String cronExpression); Date getNextFireTime(); void pauseJob(); void resumeJob(); void triggerJob(); void shutdown();  }
@Test public void assertShutdownJobIfShutdown() throws NoSuchFieldException, SchedulerException { ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); when(scheduler.isShutdown()).thenReturn(true); jobScheduleController.shutdown(); verify(schedulerFacade).releaseJobResource(); verify(scheduler, times(0)).shutdown(); }
@Test(expected = JobException.class) public void assertShutdownFailure() throws NoSuchFieldException, SchedulerException { doThrow(SchedulerException.class).when(scheduler).shutdown(); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); try { jobScheduleController.shutdown(); } finally { verify(schedulerFacade).releaseJobResource(); verify(scheduler).shutdown(); } }
@Test public void assertShutdownSuccess() throws NoSuchFieldException, SchedulerException { ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); when(scheduler.isShutdown()).thenReturn(false); jobScheduleController.shutdown(); verify(schedulerFacade).releaseJobResource(); verify(scheduler).shutdown(); }