SystemCtl { public SystemCtlEnable enable(String unit) { return new SystemCtlEnable(unit); } SystemCtl(Terminal terminal); SystemCtl withSudo(); boolean useSudo(); void daemonReload(TaskContext taskContext); SystemCtlEnable enable(String unit); SystemCtlDisable disable(String unit); SystemCtlStart start(String unit); SystemCtlStop stop(String unit); SystemCtlRestart restart(String unit); boolean serviceExists(TaskContext context, String unit); boolean isActive(TaskContext context, String unit);  }
@Test public void enable() { terminal.expectCommand("systemctl --quiet is-enabled docker 2>&1", 1, "") .expectCommand("systemctl enable docker 2>&1") .expectCommand("systemctl --quiet is-enabled docker 2>&1"); SystemCtl.SystemCtlEnable enableDockerService = new SystemCtl(terminal).enable("docker"); assertTrue(enableDockerService.converge(taskContext)); assertFalse("Already converged", enableDockerService.converge(taskContext)); }
@Test public void enableCommandFailure() { terminal.expectCommand("systemctl --quiet is-enabled docker 2>&1", 1, "") .expectCommand("systemctl enable docker 2>&1", 1, "error enabling service"); SystemCtl.SystemCtlEnable enableDockerService = new SystemCtl(terminal).enable("docker"); try { enableDockerService.converge(taskContext); fail(); } catch (ChildProcessFailureException e) { } }