### Question:
TaskManager { public boolean cancelTask(String id) { if (id == null) return false; boolean ret = taskPersister.markTaskToBeCancelled(id); if (ret && taskRunner != null) { taskRunner.cancelTask(id); } return ret; } TaskManager(String nodeId, TaskFactory taskFactory, TaskPersister taskPersister); synchronized void startTasksExecution(); synchronized void stopTasksExecution(); List<String> listSupportedTaskTypes(); String createTask(String taskType, Map<String, Object> taskConfig); TaskStatusInfo getTaskStatusInfo(String id); boolean cancelTask(String id); List<TaskStatusInfo> listTasks(String taskTypeFilter, List<TaskStatus> taskStatusFilter, int from, int size); String getNodeId(); TaskFactory getTaskFactory(); TaskPersister getTaskPersister(); TaskRunner getTaskRunner();  }### Answer:
@Test public void cancelTask() { TaskManager tested = getTested(); Mockito.when(tested.taskPersister.markTaskToBeCancelled("1")).thenReturn(true); Mockito.when(tested.taskPersister.markTaskToBeCancelled("2")).thenReturn(false); tested.cancelTask("1"); Mockito.verify(tested.taskPersister).markTaskToBeCancelled("1"); Mockito.verify(tested.taskRunner).cancelTask("1"); tested.cancelTask("2"); Mockito.verify(tested.taskPersister).markTaskToBeCancelled("1"); Mockito.verifyNoMoreInteractions(tested.taskRunner); tested.taskRunner = null; Mockito.verify(tested.taskPersister, Mockito.times(1)).markTaskToBeCancelled("1"); }