use of com.intellij.openapi.roots.RootPolicy in project intellij-community by JetBrains.
the class InheritedJdkTest method test2.
public void test2() throws Exception {
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
ModuleRootModificationUtil.setSdkInherited(myModule);
assertTrue("JDK is inherited after inheritSdk()", rootManager.isSdkInherited());
assertNull("No JDK assigned", rootManager.getSdk());
final Sdk mockJdk = IdeaTestUtil.getMockJdk17("mock 1.4");
ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(mockJdk));
final ProjectRootManagerEx projectRootManager = ProjectRootManagerEx.getInstanceEx(myProject);
ApplicationManager.getApplication().runWriteAction(() -> projectRootManager.setProjectSdk(mockJdk));
assertTrue(rootManager.isSdkInherited());
assertEquals("mockJdk inherited", mockJdk, rootManager.getSdk());
ApplicationManager.getApplication().runWriteAction(() -> projectRootManager.setProjectSdkName("jdk1"));
assertTrue(rootManager.isSdkInherited());
Assert.assertEquals("Correct non-existing JDK inherited", "jdk1", rootManager.orderEntries().process(new RootPolicy<String>() {
@Override
public String visitInheritedJdkOrderEntry(InheritedJdkOrderEntry inheritedJdkOrderEntry, String s) {
return inheritedJdkOrderEntry.getJdkName();
}
}, null));
assertNull("Non-existing JDK", rootManager.getSdk());
final Sdk jdk1 = IdeaTestUtil.getMockJdk17("jdk1");
ApplicationManager.getApplication().runWriteAction(() -> ProjectJdkTable.getInstance().addJdk(jdk1));
assertTrue(rootManager.isSdkInherited());
assertNotNull("JDK appeared", rootManager.getSdk());
assertEquals("jdk1 found", jdk1, rootManager.getSdk());
}
Aggregations