QuartzScheduler { public synchronized boolean scheduleJobIfAbsent(final String cronExpression, final QuartzJobDescription jobDescription) throws SchedulerException { requireNonNull(jobDescription, "jobDescription is null"); if (ifJobExist(jobDescription.getJobName(), jobDescription.getGroupName())) { logger.warn(String.format("can not register existing job with job name: " + "%s and group name: %s", jobDescription.getJobName(), jobDescription.getGroupName())); return false; } if (!CronExpression.isValidExpression(cronExpression)) { throw new SchedulerException( "The cron expression string <" + cronExpression + "> is not valid."); } final JobDetail job = JobBuilder.newJob(jobDescription.getJobClass()) .withIdentity(jobDescription.getJobName(), jobDescription.getGroupName()).build(); job.getJobDataMap().putAll(jobDescription.getContextMap()); final Trigger trigger = TriggerBuilder .newTrigger() .withSchedule( CronScheduleBuilder.cronSchedule(cronExpression) .withMisfireHandlingInstructionFireAndProceed() ) .build(); this.scheduler.scheduleJob(job, trigger); logger.info("Quartz Schedule with jobDetail " + job.getDescription() + " is registered."); return true; } @Inject  QuartzScheduler(final Props azProps); void start(); void shutdown(); synchronized boolean pauseJobIfPresent(final String jobName, final String groupName); synchronized boolean isJobPaused(final String jobName, final String groupName); synchronized boolean resumeJobIfPresent(final String jobName, final String groupName); synchronized boolean unscheduleJob(final String jobName, final String groupName); synchronized boolean scheduleJobIfAbsent(final String cronExpression, final QuartzJobDescription
      jobDescription); Scheduler getScheduler();  }
@Test public void testSchedulingDuplicateJob() throws Exception { scheduler.scheduleJobIfAbsent("* * * * * ?", createJobDescription()); assertThat(scheduler.scheduleJobIfAbsent("0 5 * * * ?", createJobDescription())).isFalse(); }
@Test public void testInvalidCron() { assertThatThrownBy( () -> scheduler.scheduleJobIfAbsent("0 5 * * * *", createJobDescription())) .isInstanceOf(SchedulerException.class) .hasMessageContaining("The cron expression string"); }