void () { List<String> disposeLog = new ArrayList<>(); List<String> childLog = new ArrayList<>(); class TaskWithId implements MergeableQueueTask<TaskWithId> { protected final String taskId; TaskWithId(String taskId) { this.taskId = taskId; } @Override public void perform(@NotNull ProgressIndicator indicator) { childLog.add(taskId); } @Override public void dispose() { disposeLog.add(taskId); } @Nullable @Override public TaskWithId tryMergeWith(@NotNull TaskWithId taskFromQueue) { String newId = taskFromQueue.taskId + " " + taskId; return new TaskWithId(newId); } } for (int i = 0; i < 3; i++) { myQueue.addTask(new TaskWithId(String.valueOf(i))); } runAllTasks(); Assert.assertEquals("The last child task should run, but were: " + childLog, Collections.singletonList("0 1 2"), childLog); Assert.assertEquals("All tasks must be disposed, but were: " + disposeLog, 3, disposeLog.size()); }