@Test public void registerScheduledJobThrowsExceptionWhenIdentifierIsNull() { assertThatThrownBy(() -> scheduledJobExecutor.registerScheduledJob(jobMock)) .isInstanceOf(IllegalArgumentException.class) .hasMessage("A job's identifier can't be null!"); }
public void registerScheduledJob(@NonNull ScheduledJob scheduledJob) { if(!scheduledJobIdMap.containsKey(scheduledJob)) { var jobIdentifier = scheduledJob.getJobIdentifier(); if(Objects.isNull(jobIdentifier)) { throw new IllegalArgumentException("A job's identifier can't be null!"); } var trimmedJobIdentifier = jobIdentifier.trim(); if(trimmedJobIdentifier.isEmpty()) { throw new IllegalArgumentException("A job's identifier can't contain only whitespace!"); } if(scheduledJobIdMap.containsValue(trimmedJobIdentifier)) { throw new IllegalStateException(String.format("Multiple scheduled jobs with the same job identifier '%s' found!", trimmedJobIdentifier)); } scheduledJobIdMap.put(scheduledJob, trimmedJobIdentifier); log.debug(String.format("Added scheduled job (%s) with job identifier '%s'!", scheduledJob.getClass().getName(), jobIdentifier)); } }
ScheduledJobExecutor implements ApplicationContextAware { public void registerScheduledJob(@NonNull ScheduledJob scheduledJob) { if(!scheduledJobIdMap.containsKey(scheduledJob)) { var jobIdentifier = scheduledJob.getJobIdentifier(); if(Objects.isNull(jobIdentifier)) { throw new IllegalArgumentException("A job's identifier can't be null!"); } var trimmedJobIdentifier = jobIdentifier.trim(); if(trimmedJobIdentifier.isEmpty()) { throw new IllegalArgumentException("A job's identifier can't contain only whitespace!"); } if(scheduledJobIdMap.containsValue(trimmedJobIdentifier)) { throw new IllegalStateException(String.format("Multiple scheduled jobs with the same job identifier '%s' found!", trimmedJobIdentifier)); } scheduledJobIdMap.put(scheduledJob, trimmedJobIdentifier); log.debug(String.format("Added scheduled job (%s) with job identifier '%s'!", scheduledJob.getClass().getName(), jobIdentifier)); } } }
ScheduledJobExecutor implements ApplicationContextAware { public void registerScheduledJob(@NonNull ScheduledJob scheduledJob) { if(!scheduledJobIdMap.containsKey(scheduledJob)) { var jobIdentifier = scheduledJob.getJobIdentifier(); if(Objects.isNull(jobIdentifier)) { throw new IllegalArgumentException("A job's identifier can't be null!"); } var trimmedJobIdentifier = jobIdentifier.trim(); if(trimmedJobIdentifier.isEmpty()) { throw new IllegalArgumentException("A job's identifier can't contain only whitespace!"); } if(scheduledJobIdMap.containsValue(trimmedJobIdentifier)) { throw new IllegalStateException(String.format("Multiple scheduled jobs with the same job identifier '%s' found!", trimmedJobIdentifier)); } scheduledJobIdMap.put(scheduledJob, trimmedJobIdentifier); log.debug(String.format("Added scheduled job (%s) with job identifier '%s'!", scheduledJob.getClass().getName(), jobIdentifier)); } } @Autowired  ScheduledJobExecutor(ScheduledJobLogRepository jobLogRepo, Clock clock); }
ScheduledJobExecutor implements ApplicationContextAware { public void registerScheduledJob(@NonNull ScheduledJob scheduledJob) { if(!scheduledJobIdMap.containsKey(scheduledJob)) { var jobIdentifier = scheduledJob.getJobIdentifier(); if(Objects.isNull(jobIdentifier)) { throw new IllegalArgumentException("A job's identifier can't be null!"); } var trimmedJobIdentifier = jobIdentifier.trim(); if(trimmedJobIdentifier.isEmpty()) { throw new IllegalArgumentException("A job's identifier can't contain only whitespace!"); } if(scheduledJobIdMap.containsValue(trimmedJobIdentifier)) { throw new IllegalStateException(String.format("Multiple scheduled jobs with the same job identifier '%s' found!", trimmedJobIdentifier)); } scheduledJobIdMap.put(scheduledJob, trimmedJobIdentifier); log.debug(String.format("Added scheduled job (%s) with job identifier '%s'!", scheduledJob.getClass().getName(), jobIdentifier)); } } @Autowired  ScheduledJobExecutor(ScheduledJobLogRepository jobLogRepo, Clock clock); @Scheduled( initialDelay = 0L, fixedDelay = 120_000L ) void executeJobs(); void registerScheduledJob(@NonNull ScheduledJob scheduledJob); @Override void setApplicationContext(ApplicationContext applicationContext); }
ScheduledJobExecutor implements ApplicationContextAware { public void registerScheduledJob(@NonNull ScheduledJob scheduledJob) { if(!scheduledJobIdMap.containsKey(scheduledJob)) { var jobIdentifier = scheduledJob.getJobIdentifier(); if(Objects.isNull(jobIdentifier)) { throw new IllegalArgumentException("A job's identifier can't be null!"); } var trimmedJobIdentifier = jobIdentifier.trim(); if(trimmedJobIdentifier.isEmpty()) { throw new IllegalArgumentException("A job's identifier can't contain only whitespace!"); } if(scheduledJobIdMap.containsValue(trimmedJobIdentifier)) { throw new IllegalStateException(String.format("Multiple scheduled jobs with the same job identifier '%s' found!", trimmedJobIdentifier)); } scheduledJobIdMap.put(scheduledJob, trimmedJobIdentifier); log.debug(String.format("Added scheduled job (%s) with job identifier '%s'!", scheduledJob.getClass().getName(), jobIdentifier)); } } @Autowired  ScheduledJobExecutor(ScheduledJobLogRepository jobLogRepo, Clock clock); @Scheduled( initialDelay = 0L, fixedDelay = 120_000L ) void executeJobs(); void registerScheduledJob(@NonNull ScheduledJob scheduledJob); @Override void setApplicationContext(ApplicationContext applicationContext);  }