void (final LibraryTable libraryTable) { final Module moduleA = createModule("a.iml"); final Module moduleB = createModule("b.iml"); myModuleRootListener.assertEventsCount(2); ApplicationManager.getApplication().runWriteAction(() -> { final Library libraryA = libraryTable.createLibrary("A"); final Library.ModifiableModel libraryModifiableModel = libraryA.getModifiableModel(); libraryModifiableModel.addRoot(someAbsoluteUrl("a"), OrderRootType.CLASSES); libraryModifiableModel.commit(); myModuleRootListener.assertNoEvents(); final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel(); final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel(); rootModelA.addLibraryEntry(libraryA); rootModelB.addLibraryEntry(libraryA); rootModelA.addInvalidLibrary("Q", libraryTable.getTableLevel()); rootModelB.addInvalidLibrary("Q", libraryTable.getTableLevel()); ModifiableRootModel[] rootModels = {rootModelA, rootModelB}; ModifiableModelCommitter.multiCommit(rootModels, ModuleManager.getInstance(rootModels[0].getProject()).getModifiableModel()); myModuleRootListener.assertEventsCount(1); Library.ModifiableModel libraryModifiableModel2 = libraryA.getModifiableModel(); VirtualFile file = getTempDir().createVirtualDir(); libraryModifiableModel2.addRoot(file.getUrl(), OrderRootType.CLASSES); libraryModifiableModel2.commit(); myModuleRootListener.assertEventsCount(1); libraryTable.removeLibrary(libraryA); myModuleRootListener.assertEventsCount(1); final Library libraryQ = libraryTable.createLibrary("Q"); myModuleRootListener.assertEventsCount(1); Library.ModifiableModel model = libraryQ.getModifiableModel(); model.addRoot(getTempDir().createVirtualDir(), OrderRootType.CLASSES); model.commit(); myModuleRootListener.assertEventsCount(1); libraryTable.removeLibrary(libraryQ); myModuleRootListener.assertEventsCount(1); }); }