void () { assertNull(getJavaFacade().findClass("pack.MyClass", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myModule))); final ModifiableRootModel moduleModel = ModuleRootManager.getInstance(myModule).getModifiableModel(); try { assertNotNull(moduleModel.findLibraryOrderEntry(myLib)); final Library.ModifiableModel libModel = myLib.getModifiableModel(); ApplicationManager.getApplication().runWriteAction(() -> { libModel.addRoot(myRoot, OrderRootType.CLASSES); libModel.commit(); }); assertNotNull(getJavaFacade().findClass("pack.MyClass", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myModule))); assertTrue(Arrays.asList(moduleModel.orderEntries().librariesOnly().classes().getRoots()).contains(myRoot)); } finally { ApplicationManager.getApplication().runWriteAction(() -> moduleModel.commit()); } assertNotNull(getJavaFacade().findClass("pack.MyClass", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(myModule))); }