void () { String text = """ class Foo { void m() { } <caret>} """; PsiJavaFile file = (PsiJavaFile)configureByText(JavaFileType.INSTANCE, text); PsiMethod method = file.getClasses()[0].getMethods()[0]; TextRange originalRange = method.getTextRange(); SmartPsiElementPointer pointer = createPointer(method); ApplicationManager.getApplication().runWriteAction(() -> EditorModificationUtil.insertStringAtCaret(myEditor, """ void m() { } """)); PsiDocumentManager.getInstance(myProject).commitDocument(myEditor.getDocument()); PsiElement element = pointer.getElement(); assertNotNull(element); TextRange newRange = element.getTextRange(); assertEquals(originalRange, newRange); }