void () { myFixture.configureByText("a.java", THE_CODE); String key = "ABC"; int i = THE_CODE.indexOf(key); myFixture.getEditor().getSelectionModel().setSelection(i, i+key.length()); myFixture.performEditorAction("Find"); UIUtil.dispatchAllInvocationEvents(); assertEquals(key, getSearchTextComponent().getText()); assertEquals(key, getSearchTextComponent().getSelectedText()); assertEquals(3, getSearchTextComponent().getCaretPosition()); assertTrue(getEditorSearchComponent().hasMatches()); IdeFocusManager.findInstance().requestFocus(myFixture.getEditor().getContentComponent(), false); UIUtil.dispatchAllInvocationEvents(); myFixture.performEditorAction("Find"); UIUtil.dispatchAllInvocationEvents(); assertEquals(key, getSearchTextComponent().getText()); assertEquals(key, getSearchTextComponent().getSelectedText()); assertEquals(key.length(), getSearchTextComponent().getCaretPosition()); getEditorSearchComponent().close(); key = "abcde"; i = THE_CODE.indexOf(key); myFixture.getEditor().getSelectionModel().setSelection(i, i+key.length()); int selectionStart = myFixture.getEditor().getSelectionModel().getSelectionStart(); int selectionEnd = myFixture.getEditor().getSelectionModel().getSelectionEnd(); int caret = myFixture.getEditor().getCaretModel().getOffset(); UIUtil.dispatchAllInvocationEvents(); myFixture.performEditorAction("Find"); UIUtil.dispatchAllInvocationEvents(); assertEquals(key, getSearchTextComponent().getText()); assertEquals(key, getSearchTextComponent().getSelectedText()); assertEquals(key.length(), getSearchTextComponent().getCaretPosition()); try { getSearchTextComponent().getDocument().remove(0, getSearchTextComponent().getDocument().getLength()); } catch (BadLocationException ignore) {} UIUtil.dispatchAllInvocationEvents(); assertEquals(selectionStart, myFixture.getEditor().getSelectionModel().getSelectionStart()); assertEquals(selectionEnd, myFixture.getEditor().getSelectionModel().getSelectionEnd()); assertEquals(caret, myFixture.getEditor().getCaretModel().getOffset()); }