void () { List<Integer> disposeLog = new ArrayList<>(); List<Integer> childLog = new ArrayList<>(); TaskWithEquivalentObject task = new TaskWithEquivalentObject("child") { @Override public void perform(@NotNull ProgressIndicator indicator) { childLog.add(1); } @Override public void dispose() { disposeLog.add(1); } }; myQueue.addTask(task); myQueue.disposePendingTasks(); Assert.assertEquals("The last task should only run " + childLog, Collections.emptyList(), childLog); Assert.assertEquals("older task must be disposed" + disposeLog, Arrays.asList(1), disposeLog); runAllTasks(); Assert.assertEquals("The last task should only run " + childLog, Collections.emptyList(), childLog); Assert.assertEquals("older task must be disposed" + disposeLog, Arrays.asList(1), disposeLog); }