ScheduledJobExecutor implements ApplicationContextAware { boolean shouldAutoRegister(ScheduledJob scheduledJob) { var autoRegisteredAnnotation = scheduledJob.getClass().getAnnotation(AutoRegistered.class); if(Objects.isNull(autoRegisteredAnnotation)) { return true; } else { return autoRegisteredAnnotation.value(); } } @Autowired  ScheduledJobExecutor(ScheduledJobLogRepository jobLogRepo, Clock clock); @Scheduled( initialDelay = 0L, fixedDelay = 120_000L ) void executeJobs(); void registerScheduledJob(@NonNull ScheduledJob scheduledJob); @Override void setApplicationContext(ApplicationContext applicationContext);  }
@Test public void shouldAutoRegisterReturnsTrueWhenClassNotAnnotated() { var job = new NonAnnotatedJob(); var actualShouldAutoRegister = scheduledJobExecutor.shouldAutoRegister(job); assertThat(actualShouldAutoRegister).isTrue(); }
@Test public void shouldAutoRegisterReturnsTrueWhenAnnotatedAndValueIsTrue() { var job = new AnnotatedJob(); var actualShouldAutoRegister = scheduledJobExecutor.shouldAutoRegister(job); assertThat(actualShouldAutoRegister).isTrue(); }
@Test public void shouldAutoRegisterReturnsFalseWhenAnnotatedAndValueIsFalse() { var job = new NonAutoRegisteredJob(); var actualShouldAutoRegister = scheduledJobExecutor.shouldAutoRegister(job); assertThat(actualShouldAutoRegister).isFalse(); }