void () { final PsiJavaFile file = (PsiJavaFile)myFixture.addFileToProject("Foo.java", "class Foo {}"); WriteCommandAction.runWriteCommandAction(getProject(), (Computable<PsiElement>)() -> file.getImportList().add( JavaPsiFacade.getElementFactory(getProject()).createImportStatementOnDemand("java.util"))); PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting(); WriteCommandAction.runWriteCommandAction(getProject(), () -> getPsiManager().reloadFromDisk(file)); assert findClass("Foo") != null; }