void () { final PsiFile psiFile = myFixture.addFileToProject("Foo.java", "class Foo {}"); GlobalSearchScope scope = GlobalSearchScope.allScope(getProject()); assert FileDocumentManager.getInstance().getUnsavedDocuments().length == 0; WriteCommandAction.runWriteCommandAction(getProject(), (Computable<PsiElement>)() -> ((PsiJavaFile)psiFile).getImportList() .add(getElementFactory().createImportStatementOnDemand("java.io"))); GCUtil.tryGcSoftlyReachableObjects(); assert JavaPsiFacade.getInstance(getProject()).findClass("Foo", scope) != null; assert ((FileManagerImpl)getPsiManager().getFileManager()).getCachedDirectory(psiFile.getVirtualFile().getParent()) == null; WriteCommandAction.runWriteCommandAction(getProject(),() ->{ assert psiFile.setName("Foo1.java").equals(psiFile); }); assert FileDocumentManager.getInstance().getUnsavedDocuments().length > 0; assert JavaPsiFacade.getInstance(getProject()).findClass("Foo", scope) != null; }