@Test
public void testCleanOldJobsMultipleJobs() {

    Long jobTimeoutTime = 1L;
    jobSupervisor = new JobSupervisor(jobDAOProvider, jobTimeoutTime);
    List<Long> jobIDs = Arrays.asList(1L, 2L, 3L);
    when(jobDaoMock.getAllJobIds(JobStatus.STARTED)).thenReturn(jobIDs.iterator());
    Job pastObsoleteJobMock = mock(Job.class);
    Job pastActiveMock = mock(Job.class);
    Job futureActiveMock = mock(Job.class);
    when(jobDaoMock.read(1L)).thenReturn(pastObsoleteJobMock);
    when(jobDaoMock.read(2L)).thenReturn(pastActiveMock);
    when(jobDaoMock.read(3L)).thenReturn(futureActiveMock);
    Date inTheObsoletePast = new Date(System.currentTimeMillis() - 10000);
    Date inTheActivePast = new Date(System.currentTimeMillis() - 1);
    Date inTheActiveFuture = new Date(System.currentTimeMillis() + 10000);
    when(pastObsoleteJobMock.getActualStart()).thenReturn(inTheObsoletePast);
    when(pastActiveMock.getActualStart()).thenReturn(inTheActivePast);
    when(futureActiveMock.getActualStart()).thenReturn(inTheActiveFuture);
    jobSupervisor.cleanOldJobs();
    verify(jobDaoMock).getAllJobIds(JobStatus.STARTED);
    verify(jobDaoMock).read(jobIDs.get(0));
    verify(jobDaoMock).read(jobIDs.get(1));
    verify(jobDaoMock).read(jobIDs.get(2));
    verify(pastObsoleteJobMock).getActualStart();
    verify(pastActiveMock).getActualStart();
    verify(futureActiveMock).getActualStart();
    verify(pastObsoleteJobMock).setStatus(JobStatus.FAILED);
    verify(pastObsoleteJobMock).appendHarvestErrors(Matchers.any(String.class));
    verifyNoMoreInteractions(pastActiveMock, futureActiveMock);
    verify(jobDaoMock).update(pastObsoleteJobMock);
    verifyNoMoreInteractions(jobDaoMock);
}