void () { @Language("JAVA") String text = "class S {\n" + "}"; final PsiFile file = configureByText(JavaFileType.INSTANCE, text); PsiClass aClass = ((PsiJavaFile)file).getClasses()[0]; WriteCommandAction.runWriteCommandAction(getProject(), () -> insertString(getEditor().getDocument(), 0, "import java.util.Map;\n")); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); PsiClass aClass2 = ((PsiJavaFile)file).getClasses()[0]; assertSame(aClass, aClass2); }