JobMetaService { public Set<RunningJob> runningJobs() { final Set<RunningJob> runningJobs = new HashSet<>(); jobMetaRepository.findAllJobTypes() .forEach(jobType -> { final String jobId = jobMetaRepository.getRunningJob(jobType); if (jobId != null) { runningJobs.add(new RunningJob(jobId, jobType)); } }); return runningJobs; } @Autowired  JobMetaService(final JobMetaRepository jobMetaRepository,
                          final JobMutexGroups mutexGroups); void aquireRunLock(final String jobId, final String jobType); void releaseRunLock(final String jobType); Set<RunningJob> runningJobs(); void disable(final String jobType, final String comment); void enable(final String jobType); JobMeta getJobMeta(final String jobType);  }
@Test public void shouldReturnRunningJobsDocument() { when(jobMetaRepository.findAllJobTypes()).thenReturn(new HashSet<>(asList("someType", "someOtherType"))); when(jobMetaRepository.getRunningJob("someType")).thenReturn("someId"); when(jobMetaRepository.getRunningJob("someOtherType")).thenReturn("someOtherId"); assertThat(jobMetaService.runningJobs(), containsInAnyOrder( new RunningJob("someId", "someType"), new RunningJob("someOtherId", "someOtherType") )); }