void () { File root = new File(FileUtil.getTempDirectory()); File dir1 = new File(root, "dir1"); assertTrue(dir1.mkdirs()); VirtualFile vDir1 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir1); assertNotNull(vDir1); Module moduleA = createModule("a.iml"); myModuleRootListener.reset(); ModuleRootModificationUtil.addContentRoot(moduleA, vDir1.getPath()); UIUtil.dispatchAllInvocationEvents(); myModuleRootListener.assertEventsCount(1); assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir1); VfsTestUtil.deleteFile(vDir1); myModuleRootListener.assertEventsCount(1); assertEmpty(ModuleRootManager.getInstance(moduleA).getContentRoots()); File dir2 = new File(root, "dir2"); assertTrue(dir2.mkdirs()); VirtualFile vDir2 = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir2); assertNotNull(vDir2); rename(vDir2, "dir1"); myModuleRootListener.assertEventsCount(1); assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2); // when the existing root is renamed, it remains a root rename(vDir2, "dir2"); myModuleRootListener.assertEventsCount(1); assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2); // and event if it is moved, it's still a root File subdir = new File(root, "subdir"); assertTrue(subdir.mkdirs()); VirtualFile vSubdir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(subdir); assertNotNull(vSubdir); move(vDir2, vSubdir); myModuleRootListener.assertEventsCount(1); assertSameElements(ModuleRootManager.getInstance(moduleA).getContentRoots(), vDir2); }