void () { final MessageBusConnection connection = myProject.getMessageBus().connect(); final ModuleManager moduleManager = ModuleManager.getInstance(myProject); final MyModuleListener moduleListener = new MyModuleListener(); connection.subscribe(ModuleListener.TOPIC, moduleListener); Path dir = ProjectKt.getStateStore(myProject).getProjectBasePath(); final Module moduleA; final Module moduleB; { final ModifiableModuleModel moduleModel = moduleManager.getModifiableModel(); moduleA = moduleModel.newModule(dir.resolve("a.iml"), StdModuleTypes.JAVA.getId()); moduleB = moduleModel.newModule(dir.resolve("b.iml"), StdModuleTypes.JAVA.getId()); final ModifiableRootModel rootModelA = ModuleRootManager.getInstance(moduleA).getModifiableModel(); final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel(); rootModelB.addModuleOrderEntry(moduleA); final ContentEntry contentEntryA = rootModelA.addContentEntry(getVirtualFileInTestData("a")); contentEntryA.addSourceFolder(getVirtualFileInTestData("a/src"), false); final ContentEntry contentEntryB = rootModelB.addContentEntry(getVirtualFileInTestData("b")); contentEntryB.addSourceFolder(getVirtualFileInTestData("b/src"), false); ApplicationManager.getApplication().runWriteAction(() -> ModifiableModelCommitter.multiCommit(new ModifiableRootModel[]{rootModelB, rootModelA}, moduleModel)); } final JavaPsiFacade psiManager = getJavaFacade(); assertNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleA))); assertNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleB))); assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleScope(moduleA))); assertNotNull(psiManager.findClass("q.A", GlobalSearchScope.moduleWithDependenciesScope(moduleB))); assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleScope(moduleB))); assertNotNull(psiManager.findClass("j.B", GlobalSearchScope.moduleWithDependenciesScope(moduleB))); moduleManager.disposeModule(moduleB); moduleManager.disposeModule(moduleA); moduleListener.assertCorrectEvents(new String[][]{{"+b", "+a"}, {"-b"}, {"-a"}}); connection.disconnect(); }