### Question:
TaskRunner extends Thread { protected void interruptRunningTasks() { boolean interruptedSomething = false; synchronized (runningTasks) { for (Task task : runningTasks.values()) { if (task.isAlive()) { task.interrupt(); interruptedSomething = true; } } } if (interruptedSomething) { log.info("Giving some time for executed tasks to be finished"); try { Thread.sleep(2000); } catch (InterruptedException e) { } } } TaskRunner(String nodeId, TaskFactory taskFactory, TaskPersister taskPersister); protected  TaskRunner(); @Override void run(); void cancelTask(String taskId); void notifyNewTaskAvailableForRun();  }### Answer:
@Test public void interruptRunningTasks() throws InterruptedException { TaskRunner tested = getTested(); tested.runningTasks.put("t1", createTaskMock(true)); tested.runningTasks.put("t2", createTaskMock(false)); tested.runningTasks.put("t3", createTaskMock(true)); tested.runningTasks.put("t4", createTaskMock(false)); tested.runningTasks.put("t5", createTaskMock(true)); tested.runningTasks.put("t6", createTaskMock(true)); Thread.sleep(200); tested.interruptRunningTasks(); for (Task task : tested.runningTasks.values()) { Assert.assertTrue(!task.isAlive() || task.isInterrupted()); } }