void () { // it's a stress test to disable test checks that load file content prematurely (AbstractFileViewProvider.checkLengthConsistency) PsiFile file = myFixture.addFileToProject("a.java", "class Foo {}"); myFixture.getPsiManager().addPsiTreeChangeListener(new PsiTreeChangeAdapter() { @Override public void childrenChanged(@NotNull PsiTreeChangeEvent event) { PsiElement parent = event.getParent(); if (parent == file) { assertNotNull(file.getNode()); } } }, getTestRootDisposable()); WriteCommandAction.runWriteCommandAction(getProject(), () -> { Document document = file.getViewProvider().getDocument(); document.insertString(0, " "); PsiDocumentManager.getInstance(getProject()).commitDocument(document); }); assertEquals(" class Foo {}", file.getText()); }