void () { PsiFile srcFile = myFixture.addFileToProject("A.java", "class A {}"); assert findClass("A") != null; final Document document = FileDocumentManager.getInstance().getDocument(srcFile.getVirtualFile()); WriteCommandAction.runWriteCommandAction(getProject(), () -> document.replaceString(0, document.getTextLength(), "class B {}")); assertNotNull(findClass("A")); PsiDocumentManager.getInstance(getProject()).commitDocument(document); assertNull(findClass("A")); assertNotNull(findClass("B")); WriteCommandAction.runWriteCommandAction(getProject(), () -> document.replaceString(0, document.getTextLength(), "class C {}")); assertNotNull(findClass("B")); FileDocumentManager.getInstance().saveDocument(document); PsiDocumentManager.getInstance(getProject()).commitDocument(document); assertNull(findClass("B")); assertNotNull(findClass("C")); }