void () { final PsiFile file = myFixture.addFileToProject("a.java", "class Foo {}"); WriteCommandAction.runWriteCommandAction(getProject(), () -> { assert findClass("Foo") != null; file.getViewProvider().getDocument().setText(""); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); file.getViewProvider().getDocument().setText("class Foo {}"); FileDocumentManager.getInstance().saveAllDocuments(); assert findClass("Foo") == null; }); }