void () { Document document = getDocument(findFile(createFile())); CompletableFuture<Boolean> called = new CompletableFuture<>(); WriteCommandAction.runWriteCommandAction(myProject, () -> { document.insertString(0, " "); ApplicationManager.getApplication().invokeLater(() -> { LaterInvocator.enterModal(this); assertFalse(TransactionGuard.getInstance().isWriteSafeModality(ModalityState.defaultModalityState())); getPsiDocumentManager().performWhenAllCommitted(() -> called.complete(true)); waitForCommits(); assertFalse(called.isDone()); }, ModalityState.any()); }); UIUtil.dispatchAllInvocationEvents(); LaterInvocator.leaveModal(this); assertTrue(PlatformTestUtil.waitForFuture(called, 10_000)); }