JobControl { public JobControl(JobControlState state) { this.state = Objects.requireNonNull(state); } JobControl(JobControlState state); void started(String jobSimpleClassName, Maintainer maintainer); Set<String> jobs(); Set<String> inactiveJobs(); boolean isActive(String jobSimpleClassName); void run(String jobSimpleClassName); Mutex lockJob(String jobSimpleClassName);  }
@Test public void testJobControl() { JobControlStateMock state = new JobControlStateMock(); JobControl jobControl = new JobControl(state); String job1 = "Job1"; String job2 = "Job2"; TestMaintainer maintainer1 = new TestMaintainer(job1, jobControl); TestMaintainer maintainer2 = new TestMaintainer(job2, jobControl); assertEquals(2, jobControl.jobs().size()); assertTrue(jobControl.jobs().contains(job1)); assertTrue(jobControl.jobs().contains(job2)); assertTrue(jobControl.isActive(job1)); assertTrue(jobControl.isActive(job2)); state.setActive(job1, false); assertFalse(jobControl.isActive(job1)); assertTrue(jobControl.isActive(job2)); state.setActive(job2, false); assertFalse(jobControl.isActive(job1)); assertFalse(jobControl.isActive(job2)); state.setActive(job1, true); assertTrue(jobControl.isActive(job1)); assertFalse(jobControl.isActive(job2)); state.setActive(job2, true); assertTrue(jobControl.isActive(job1)); assertTrue(jobControl.isActive(job2)); jobControl.run(job1); jobControl.run(job1); assertEquals(2, maintainer1.totalRuns()); jobControl.run(job2); assertEquals(1, maintainer2.totalRuns()); state.setActive(job1, false); jobControl.run(job1); assertEquals(3, maintainer1.totalRuns()); }