JobScheduleController { public void triggerJob() { try { if (!scheduler.isShutdown()) { scheduler.triggerJob(jobDetail.getKey()); } } 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 assertTriggerJobIfShutdown() throws NoSuchFieldException, SchedulerException { JobKey jobKey = new JobKey("testJob"); when(jobDetail.getKey()).thenReturn(jobKey); when(scheduler.isShutdown()).thenReturn(true); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); ReflectionUtils.setFieldValue(jobScheduleController, "jobDetail", jobDetail); jobScheduleController.triggerJob(); verify(jobDetail, times(0)).getKey(); verify(scheduler, times(0)).triggerJob(jobKey); }
@Test(expected = JobException.class) public void assertTriggerJobFailure() throws NoSuchFieldException, SchedulerException { JobKey jobKey = new JobKey("testJob"); when(jobDetail.getKey()).thenReturn(jobKey); doThrow(SchedulerException.class).when(scheduler).triggerJob(jobKey); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); ReflectionUtils.setFieldValue(jobScheduleController, "jobDetail", jobDetail); try { jobScheduleController.triggerJob(); } finally { verify(jobDetail).getKey(); verify(scheduler).triggerJob(jobKey); } }
@Test public void assertTriggerJobSuccess() throws NoSuchFieldException, SchedulerException { JobKey jobKey = new JobKey("testJob"); when(jobDetail.getKey()).thenReturn(jobKey); when(scheduler.isShutdown()).thenReturn(false); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); ReflectionUtils.setFieldValue(jobScheduleController, "jobDetail", jobDetail); jobScheduleController.triggerJob(); verify(jobDetail).getKey(); verify(scheduler).triggerJob(jobKey); }