void () { myFixture.addClass("package p.p1; public class C {}"); myFixture.addClass("package p.p1; public class D {}"); myFixture.addClass("package p.p2;\n" + "public class B{\n" + " public enum C { None, Some, All }\n" + " public static final int JUNK = 0;\n" + "}"); myFixture.configureByText(JavaFileType.INSTANCE, "package p.p2;\n" + "import p.p1.*;\n" + "import static p.p2.B.*;\n" + "import static p.p2.B.C;\n" + "public class A {\n" + " public static void main( String[] args )\n" + " {\n" + " new D();\n" + " System.out.println( C.None );\n" + " System.out.println( JUNK );\n" + " }\n" + "}"); JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject()); javaSettings.PACKAGES_TO_USE_IMPORT_ON_DEMAND.addEntry(new PackageEntry(false, "p", true)); WriteCommandAction.runWriteCommandAction(getProject(), () -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile())); myFixture.checkResult("package p.p2;\n" + "\n" + "import p.p1.*;\n" + "\n" + "import static p.p2.B.C;\n" + "import static p.p2.B.*;\n" + "\n" + "public class A {\n" + " public static void main( String[] args )\n" + " {\n" + " new D();\n" + " System.out.println( C.None );\n" + " System.out.println( JUNK );\n" + " }\n" + "}"); }