### Question:
JobExecutionService { public Collection<JobExecution> jobExecutions(Optional<String> jobNameRegexp, Optional<String> exitCode, int maxNumberOfExecutionsPerJobName) { logger.debug("Getting job executions(jobNameRegexp={}, exitCode={}, maxNumberOfExecutionsPerJobName={})", jobNameRegexp, exitCode, maxNumberOfExecutionsPerJobName); return jobExecutionProvider.getJobExecutions(jobNameRegexp, exitCode, maxNumberOfExecutionsPerJobName).stream() .map(JobExecution::fromSpring) .collect(Collectors.toList()); } @Autowired  JobExecutionService(JobExplorer jobExplorer, CachedJobExecutionProvider jobExecutionProvider, AdHocStarter adHocStarter); JobExecution jobExecution(long executionId); Collection<JobExecution> jobExecutions(Optional<String> jobNameRegexp,
                                                  Optional<String> exitCode,
                                                  int maxNumberOfExecutionsPerJobName); JobExecution launch(JobConfig jobConfig); Job job(String jobName);  }### Answer:
@Test public void jobExecutionsAll() { Collection<JobExecution> jes = jobExecutionService.jobExecutions(empty(), empty(), MAX_VALUE); Assertions.assertThat(jes).hasSize(6); }
@Test public void jobExecutionsJobNameRegexp() { Collection<JobExecution> jes = jobExecutionService.jobExecutions(Optional.of("j1"), empty(), MAX_VALUE); Assertions.assertThat(jes).hasSize(2); }
@Test public void jobExecutionsStatus() { Collection<JobExecution> jes = jobExecutionService.jobExecutions(Optional.of("j1"), Optional.of(ExitStatus.COMPLETED.getExitCode()), MAX_VALUE); Assertions.assertThat(jes).hasSize(1); }
@Test public void jobExecutionsMaxNumberOfJobInstancesFailed() { Collection<JobExecution> jes = jobExecutionService.jobExecutions(empty(), Optional.of(ExitStatus.FAILED.getExitCode()), 1); Assertions.assertThat(jes).hasSize(2); Assertions.assertThat(jes).extracting(je -> je.getExitCode()).allMatch(s -> s.equals("FAILED")); }
@Test public void jobExecutionsMaxNumberOfJobInstancesCompleted() { Collection<JobExecution> jes = jobExecutionService.jobExecutions(empty(), Optional.of(ExitStatus.COMPLETED.getExitCode()), 1); Assertions.assertThat(jes).hasSize(2); Assertions.assertThat(jes).extracting(je -> je.getJobName()).containsExactly(JOB_NAME_2, JOB_NAME_1); }