void () { String fileText = "import java.util.ArrayList;\n" + "public class A {\n" + " public static void main( String[] args)\n" + " {\n" + " ArrayList\n" + " }\n" + "}"; myFixture.configureByText(JavaFileType.INSTANCE, fileText); WriteCommandAction.runWriteCommandAction(getProject(), () -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile())); myFixture.checkResult(fileText); }