void () { myFileDataProviderForSearch = new MyFileDataProviderForSearch(); myRangeSearch = new RangeSearch(new MockVirtualFile(FILE_NAME), getProject(), new MyRangeSearchCallback()); myStopRangeSearchAction = new StopRangeSearchAction(myRangeSearch); myFindFurtherAction = new FindFurtherAction(true, myRangeSearch); SearchTaskOptions options = new SearchTaskOptions(); options.setStringToFind("a"); myNeedToAbortSearch = true; myRangeSearch.addEdtRangeSearchEventsListener(new RangeSearch.EdtRangeSearchEventsListener() { @Override public void onSearchStopped() { onStopped(this); } @Override public void onSearchFinished() { Assert.fail("Was called onSearchFinished(), however shouldn't be"); } }); isAllDoneAsExpected = false; myRangeSearch.runNewSearch(options, myFileDataProviderForSearch); UIUtil.dispatchAllInvocationEvents(); /* This line shouldn't be executed before onFinished() will be done. * See com.intellij.openapi.progress.impl.CoreProgressManager#run, * where in tests "task.isHeadless()" will be true. * This causes "strange" order of execution of EDT-tasks. */ if (!isAllDoneAsExpected) { Assert.fail("wrong order of tasks execution\n" + ThreadDumper.dumpThreadsToString()); } }