void () { VirtualFile libDir = createChildDirectory(getOrCreateProjectBaseDir(), "myLib"); LibraryTable table = getProjectLibraryTable(); Library library = WriteAction.compute(() -> table.createLibrary("myLib")); Library.ModifiableModel model = library.getModifiableModel(); VirtualFile libJar = getVirtualFile(new File(PathManagerEx.getTestDataPath() + OrderEntryTest.BASE_PATH + "lib/lib.jar")); copy(libJar, libDir, libJar.getName()); model.addJarDirectory(libDir.getUrl(), false, OrderRootType.CLASSES); commit(model); ModuleRootModificationUtil.updateModel(getModule(), m -> m.addLibraryEntry(library)); assertSize(1, library.getUrls(OrderRootType.CLASSES)); assertSameElements(library.getUrls(OrderRootType.CLASSES), libDir.getUrl()); assertSize(1, library.getFiles(OrderRootType.CLASSES)); assertEquals(libDir.getPath() + "/" + libJar.getName() + "!/", library.getFiles(OrderRootType.CLASSES)[0].getPath()); PsiClass aClass = JavaPsiFacade.getInstance(getProject()).findClass("l.InLib", GlobalSearchScope.allScope(getProject())); assertNotNull(aClass); // wait until unlock the file? while (!FileUtil.delete(new File(libDir.getPath(),"lib.jar"))) { } UIUtil.dispatchAllInvocationEvents(); libDir.refresh(false, false); UIUtil.dispatchAllInvocationEvents(); assertNull(libDir.findChild("lib.jar")); aClass = JavaPsiFacade.getInstance(getProject()).findClass("l.InLib", GlobalSearchScope.allScope(getProject())); assertNull(aClass); copy(libJar, libDir, libJar.getName()); UIUtil.dispatchAllInvocationEvents(); aClass = JavaPsiFacade.getInstance(getProject()).findClass("l.InLib", GlobalSearchScope.allScope(getProject())); assertNotNull(aClass); ModuleRootModificationUtil.updateModel(getModule(), m -> m.removeOrderEntry(m.findLibraryOrderEntry(library))); aClass = JavaPsiFacade.getInstance(getProject()).findClass("l.InLib", GlobalSearchScope.allScope(getProject())); assertNull(aClass); }