void () { final VirtualFile file = new MockVirtualFile("test.txt", "test\rtest") { @NotNull @Override public OutputStream getOutputStream(final Object requestor, final long newModificationStamp, long newTimeStamp) { final VirtualFile self = this; return new ByteArrayOutputStream() { @Override public void close() throws IOException { super.close(); long oldStamp = getModificationStamp(); setModificationStamp(newModificationStamp); setText(toString()); myDocumentManager.contentsChanged(new VFileContentChangeEvent(null, self, oldStamp, getModificationStamp())); } }; } }; final Document document = myDocumentManager.getDocument(file); assertNotNull(file.toString(), document); WriteCommandAction.runWriteCommandAction(myProject, () -> document.insertString(0, "xxx")); final long stamp = document.getModificationStamp(); myDocumentManager.saveAllDocuments(); assertEquals(stamp, document.getModificationStamp()); }