void () { AtomicReference<Boolean> isDisposed = new AtomicReference<>(); myQueue.addTask(new TaskWithEquivalentObject("any") { @Override public void perform(@NotNull ProgressIndicator indicator) { } @Override public void dispose() { isDisposed.set(true); } }); MergingTaskQueue.QueuedTask<?> task = myQueue.extractNextTask(); myQueue.disposePendingTasks(); Assert.assertNull(isDisposed.get()); try { task.executeTask(); Assert.fail(); } catch (ProcessCanceledException ignore) { //OK } finally { task.close(); } Assert.assertEquals(Boolean.TRUE, isDisposed.get()); }