### Question:
TaskRunner extends Thread { public void cancelTask(String taskId) { synchronized (runningTasks) { Task t = runningTasks.get(taskId); if (t != null && t.isAlive()) { t.setCanceled(true); t.interrupt(); } } } TaskRunner(String nodeId, TaskFactory taskFactory, TaskPersister taskPersister); protected  TaskRunner(); @Override void run(); void cancelTask(String taskId); void notifyNewTaskAvailableForRun();  }### Answer:
@Test public void cancelTask() throws InterruptedException { TaskRunner tested = getTested(); tested.cancelTask("unknown"); Task t1 = createTaskMock(true); Task t2 = createTaskMock(false); tested.runningTasks.put("t1", t1); tested.runningTasks.put("t2", t2); Thread.sleep(700); tested.cancelTask("t1"); tested.cancelTask("t2"); Assert.assertTrue(t1.isCanceledOrInterrupted()); Assert.assertFalse(t2.isCanceledOrInterrupted()); }