void () { ApplicationManager.getApplication().runWriteAction(() -> { final Module moduleA = createModule("a.iml"); final Module moduleB = createModule("b.iml"); myModuleRootListener.assertEventsCount(2); final Sdk jdk = ProjectJdkTable.getInstance().createSdk("new-jdk", JavaSdk.getInstance()); final Sdk unused = ProjectJdkTable.getInstance().createSdk("unused", JavaSdk.getInstance()); ProjectJdkTable.getInstance().addJdk(jdk, getTestRootDisposable()); ProjectJdkTable.getInstance().addJdk(unused, getTestRootDisposable()); myModuleRootListener.assertNoEvents(); final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel(); final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel(); rootModelA.setSdk(jdk); rootModelB.setSdk(jdk); ModifiableRootModel[] rootModels = {rootModelA, rootModelB}; ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel()); myModuleRootListener.assertEventsCount(1); final SdkModificator sdkModificator = jdk.getSdkModificator(); sdkModificator.addRoot(getTempDir().createVirtualDir(), OrderRootType.CLASSES); sdkModificator.commitChanges(); myModuleRootListener.assertEventsCount(1); final SdkModificator sdkModificator2 = unused.getSdkModificator(); sdkModificator2.addRoot(getTempDir().createVirtualDir(), OrderRootType.CLASSES); sdkModificator2.commitChanges(); myModuleRootListener.assertNoEvents(); }); }