### Question:
PDSBatchTriggerService { @Scheduled(initialDelayString = "${sechub.pds.config.trigger.nextjob.initialdelay:" + DEFAULT_INITIAL_DELAY_MILLIS + "}", fixedDelayString = "${sechub.pds.config.trigger.nextjob.delay:" + DEFAULT_FIXED_DELAY_MILLIS + "}") @Transactional public void triggerExecutionOfNextJob() { if (!schedulingEnabled) { LOG.trace("Trigger execution of next job canceled, because scheduling disabled."); return; } LOG.trace("Trigger execution of next job started."); if (executionService.isQueueFull()) { LOG.debug("Execution service is not able to execute next job, so cancel here"); return; } Optional<PDSJob> nextJob = repository.findNextJobToExecute(); if (!nextJob.isPresent()) { LOG.trace("No next job present"); return; } PDSJob pdsJob = nextJob.get(); pdsJob.setState(PDSJobStatusState.QUEUED); executionService.addToExecutionQueueAsynchron(pdsJob.getUUID()); }  @Scheduled(initialDelayString = "${sechub.pds.config.trigger.nextjob.initialdelay:" + DEFAULT_INITIAL_DELAY_MILLIS + "}", fixedDelayString = "${sechub.pds.config.trigger.nextjob.delay:" + DEFAULT_FIXED_DELAY_MILLIS + "}") @Transactional void triggerExecutionOfNextJob();  }### Answer:
@Test public void a_job_found_for_next_execution_is_changed_to_state_QUEUED() { PDSJob job = new PDSJob(); job.setState(PDSJobStatusState.READY_TO_START); when(repository.findNextJobToExecute()).thenReturn(Optional.of(job)); assertEquals(PDSJobStatusState.READY_TO_START, job.getState()); serviceToTest.triggerExecutionOfNextJob(); assertEquals(PDSJobStatusState.QUEUED, job.getState()); }
@Test public void a_job_found_for_next_execution_but_scheduling_disabled_job_is_not_changed() { serviceToTest.schedulingEnabled=false; PDSJob job = new PDSJob(); job.setState(PDSJobStatusState.READY_TO_START); when(repository.findNextJobToExecute()).thenReturn(Optional.of(job)); assertEquals(PDSJobStatusState.READY_TO_START, job.getState()); serviceToTest.triggerExecutionOfNextJob(); assertEquals(PDSJobStatusState.READY_TO_START, job.getState()); }
@Test public void a_job_found_for_next_execution_but_scheduling_disabled_executor_service_not_called() { serviceToTest.schedulingEnabled=false; UUID uuid = UUID.randomUUID(); PDSJob job = mock(PDSJob.class); when(job.getUUID()).thenReturn(uuid); when(repository.findNextJobToExecute()).thenReturn(Optional.of(job)); serviceToTest.triggerExecutionOfNextJob(); verify(executionService,never()).addToExecutionQueueAsynchron(uuid); }
@Test public void a_job_found_for_next_execution_executor_service_called() { UUID uuid = UUID.randomUUID(); PDSJob job = mock(PDSJob.class); when(job.getUUID()).thenReturn(uuid); when(repository.findNextJobToExecute()).thenReturn(Optional.of(job)); serviceToTest.triggerExecutionOfNextJob(); verify(executionService).addToExecutionQueueAsynchron(uuid); }