void () { Ref<Boolean> gotIt = new Ref<>(false); PsiTreeChangeAdapter listener = new PsiTreeChangeAdapter() { @Override public void childReplaced(@NotNull PsiTreeChangeEvent event) { gotIt.set(true); } }; getPsiManager().addPsiTreeChangeListener(listener, getTestRootDisposable()); Project project = getProject(); GroovyFile file = GroovyPsiElementFactory.getInstance(project).createGroovyFile("/** This is doc comment*/class C{}", true, null); PsiDocumentManager docManager = PsiDocumentManager.getInstance(project); Document doc = docManager.getDocument(file); assertNotNull(doc); CommandProcessor.getInstance().executeCommand( project, () -> ApplicationManager.getApplication().runWriteAction(() -> { doc.insertString(3, " "); docManager.commitDocument(doc); }), "file text set", this ); assertTrue(gotIt.get()); }