SchedulableJobValidator { public static void validateRunOnceSchedulableJob(RunOnceSchedulableJob job) { notNull(job, JOB_CANNOT_BE_NULL); validateSchedulableJob(job); DateTime startDate = job.getStartDate(); DateTime currentDate = DateUtil.now(); if (job.getStartDate().isBefore(currentDate)) { String errorMessage = "Invalid RunOnceSchedulableJob. The job start date can not be in the past. \n" + " Job start date: " + startDate.toString() + " Attempted to schedule at:" + currentDate.toString(); throw new MotechSchedulerException(errorMessage, "scheduler.error.startDateInThePast", Arrays.asList(startDate.toString(), currentDate.toString())); } } private  SchedulableJobValidator(); static void validateCronSchedulableJob(CronSchedulableJob job); static void validateRepeatingSchedulableJob(RepeatingSchedulableJob job); static void validateRepeatingPeriodSchedulableJob(RepeatingPeriodSchedulableJob job); static void validateRunOnceSchedulableJob(RunOnceSchedulableJob job); static void validateDayOfWeekSchedulableJob(DayOfWeekSchedulableJob job);  }
@Test public void shouldValidateRunOnceJob() { try { fakeNow(newDateTime(2020, 7, 15, 10, 0, 0)); RunOnceSchedulableJob job = new RunOnceSchedulableJob(motechEvent, DateUtil.now().plusHours(1), false); SchedulableJobValidator.validateRunOnceSchedulableJob(job); } finally { stopFakingTime(); } }
@Test(expected = IllegalArgumentException.class) public void shouldThrowIllegalArgumentExceptionIfMotechEventIsNullInRunOnceSchedulableJob() { try { fakeNow(newDateTime(2020, 7, 15, 10, 0, 0)); RunOnceSchedulableJob job = new RunOnceSchedulableJob(null, DateUtil.now().plusHours(1), false); SchedulableJobValidator.validateRunOnceSchedulableJob(job); } finally { stopFakingTime(); } }
@Test(expected = IllegalArgumentException.class) public void shouldThrowIllegalArgumentExceptionIfStartDatesNullInRunOnceSchedulableJob() { try { fakeNow(newDateTime(2020, 7, 15, 10, 0, 0)); RunOnceSchedulableJob job = new RunOnceSchedulableJob(motechEvent, null, false); SchedulableJobValidator.validateRunOnceSchedulableJob(job); } finally { stopFakingTime(); } }
@Test(expected = MotechSchedulerException.class) public void shouldThrowMotechSchedulerExceptionIfStartDateIsInThePast() { try { fakeNow(newDateTime(2020, 7, 15, 10, 0, 0)); RunOnceSchedulableJob job = new RunOnceSchedulableJob(motechEvent, DateUtil.now().minusHours(1), false); SchedulableJobValidator.validateRunOnceSchedulableJob(job); } finally { stopFakingTime(); } }