JobScheduleController { public void rescheduleJob(final String cronExpression) { try { if (!scheduler.isShutdown()) { scheduler.rescheduleJob(TriggerKey.triggerKey(triggerIdentity), createTrigger(cronExpression)); } } 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 assertRescheduleJobIfShutdown() throws NoSuchFieldException, SchedulerException { ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); when(scheduler.isShutdown()).thenReturn(true); jobScheduleController.rescheduleJob("0/1 * * * * ?"); verify(scheduler, times(0)).rescheduleJob(eq(TriggerKey.triggerKey("testJob_Trigger")), Matchers.<Trigger>any()); }
@Test(expected = JobException.class) public void assertRescheduleJobFailure() throws NoSuchFieldException, SchedulerException { doThrow(SchedulerException.class).when(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("testJob_Trigger")), Matchers.<Trigger>any()); ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); try { jobScheduleController.rescheduleJob("0/1 * * * * ?"); } finally { verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("testJob_Trigger")), Matchers.<Trigger>any()); } }
@Test public void assertRescheduleJobSuccess() throws NoSuchFieldException, SchedulerException { ReflectionUtils.setFieldValue(jobScheduleController, "scheduler", scheduler); when(scheduler.isShutdown()).thenReturn(false); jobScheduleController.rescheduleJob("0/1 * * * * ?"); verify(scheduler).rescheduleJob(eq(TriggerKey.triggerKey("testJob_Trigger")), Matchers.<Trigger>any()); }