void () { new SdkTestCases() { { WriteAction.run(() -> { ModifiableRootModel m = ModuleRootManager.getInstance(getModule()).getModifiableModel(); m.setSdk(valid); m.commit(); ProjectRootManager.getInstance(getProject()).setProjectSdk(broken); }); final List<String> panel = detectMissingSdks(); assertThat(panel).hasSize(1).first().asString().startsWith("SdkFixInfo:InvalidSdkFixInfo { name: " + broken.getName()); } }; } private void setModuleSdk(@NotNull String sdkName, @NotNull SdkTypeId type) { setModuleSdk(sdkName, type.getName()); } private void setModuleSdk(@NotNull String sdkName, @NotNull String sdkType) { WriteAction.run(() -> { ModifiableRootModel model = ModuleRootManager.getInstance(getModule()).getModifiableModel(); model.setInvalidSdk(sdkName, sdkType); model.commit(); }); } @Override protected void setUp() throws Exception { super.setUp(); setProjectSdk2(IdeaTestUtil.getMockJdk17()); } private @NotNull List<String> detectMissingSdks() { UnknownSdkTracker.getInstance(getProject()).updateUnknownSdks(); List<String> infos = new ArrayList<>(); EditorNotificationPanel sdkNotification = SdkSetupNotificationTestBase.runOnText(myFixture, "Sample.java", "class Sample { java.lang.String foo; }"); if (sdkNotification != null) { infos.add("SdkSetupNotification:" + sdkNotification.getText()); } for (UnknownSdkFix notification : UnknownSdkEditorNotification.getInstance(getProject()).getNotifications()) { infos.add("SdkFixInfo:" + notification.toString()); } return infos; } private void setProjectSdk2(@Nullable Sdk sdk) { WriteAction.run(() -> { ProjectRootManager.getInstance(getProject()).setProjectSdk(addSdkIfNeeded(sdk)); }); } @Contract("null->null;!null->!null") private Sdk addSdkIfNeeded(Sdk sdk) { if (sdk == null) return null; ProjectJdkTable jdkTable = ProjectJdkTable.getInstance(); final Sdk foundJdk = jdkTable.findJdk(sdk.getName()); if (foundJdk != null) return sdk; ThrowableRunnable<RuntimeException> addSdk = () -> { jdkTable.addJdk(sdk, myFixture.getProjectDisposable()); }; if (ApplicationManager.getApplication().isWriteAccessAllowed()) { addSdk.run(); } else { WriteAction.run(addSdk); } return sdk; } }