void () { List<Integer> disposeLog = new ArrayList<>(); List<Integer> childLog = new ArrayList<>(); service().runTaskSynchronously(new DumbModeTaskWithEquivalentObject("parent") { @Override public void performInDumbMode(@NotNull ProgressIndicator indicator) { for (int i = 0; i < 100; i++) { int taskId = i; service().runTaskSynchronously(new DumbModeTaskWithEquivalentObject("child") { @Override public void performInDumbMode(@NotNull ProgressIndicator indicator) { childLog.add(taskId); } @Override public void dispose() { disposeLog.add(taskId); } }); } } }); Assert.assertEquals("Only one child task should run, but were: " + childLog, 1, childLog.size()); Assert.assertEquals("All tasks must be disposed, but were: " + disposeLog, 100, disposeLog.size()); }