void () { Project project = getProject(); PsiExpressionCodeFragment fragment = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment("a", null, null, true); VirtualFile file = fragment.getViewProvider().getVirtualFile(); assertInstanceOf(file, LightVirtualFile.class); ApplicationManager.getApplication().runWriteAction(() -> ProjectRootManagerEx.getInstanceEx(project). makeRootsChange(EmptyRunnable.getInstance(), RootsChangeRescanningInfo.NO_RESCAN_NEEDED)); assertSame(fragment, PsiManager.getInstance(project).findFile(file)); assertTrue(fragment.isValid()); }