### Question:
TaskRunner extends Thread { protected void removeFinished() { synchronized (runningTasks) { Set<String> rem = new HashSet<>(); for (String taskId : runningTasks.keySet()) { if (!runningTasks.get(taskId).isAlive()) { rem.add(taskId); } } if (!rem.isEmpty()) { for (String t : rem) runningTasks.remove(t); } } } TaskRunner(String nodeId, TaskFactory taskFactory, TaskPersister taskPersister); protected  TaskRunner(); @Override void run(); void cancelTask(String taskId); void notifyNewTaskAvailableForRun();  }### Answer:
@Test public void removeFinished() throws InterruptedException { TaskRunner tested = getTested(); tested.removeFinished(); Assert.assertEquals(0, tested.runningTasks.size()); Task t1 = createTaskMock(true); Task t3 = createTaskMock(true); tested.runningTasks.put("t1", t1); tested.runningTasks.put("t2", createTaskMock(false)); tested.runningTasks.put("t3", t3); tested.runningTasks.put("t4", createTaskMock(false)); Thread.sleep(1000); tested.removeFinished(); Assert.assertEquals(2, tested.runningTasks.size()); Assert.assertEquals(t1, tested.runningTasks.get("t1")); Assert.assertEquals(t3, tested.runningTasks.get("t3")); }