void () { final VirtualFile vFile = myFixture.addClass("class Foo {}").getContainingFile().getVirtualFile(); ((VirtualFileSystemEntry)vFile).setModificationStamp(0);// as unchanged file final Document document = FileDocumentManager.getInstance().getDocument(vFile); assertNotNull(document); assert document.getModificationStamp() == 0; assertNotNull(findClass("Foo")); WriteCommandAction.runWriteCommandAction(getProject(), () -> { document.insertString(0, "import Bar;\n"); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); assertNotNull(findClass("Foo")); }); final UndoManager undoManager = UndoManager.getInstance(getProject()); final FileEditor selectedEditor = FileEditorManager.getInstance(getProject()).openFile(vFile, false)[0]; ((UndoManagerImpl)undoManager).setOverriddenEditorProvider(new CurrentEditorProvider() { @Override public FileEditor getCurrentEditor(@Nullable Project project) { return selectedEditor; } }); assertTrue(undoManager.isUndoAvailable(selectedEditor)); FileDocumentManager.getInstance().saveDocument(document); undoManager.undo(selectedEditor); assertNotNull(findClass("Foo")); }