@Override public void run(@NotNull ProgressIndicator indicator) { try { while (installationCompletionLatch.getCount() > 0) { // wait interruptibility to check for user cancel each second. installationCompletionLatch.await(1, SECONDS); if (checkIfCancelled()) { sdkLogging.onUserCancel(); break; } } } catch (InterruptedException e) { /* valid cancellation exception, no handling needed. */ } finally { // process UI related activities ApplicationManager.getApplication() .invokeLater( () -> { // remove the notification listener regardless of waiting outcome. cloudSdkService.removeStatusUpdateListener(sdkStatusUpdateListener); // process logging and error notifications. handleErrors(sdkLogging); }); // run the activity after wait is over, regardless of outcome. afterWaitComplete.run(); } } });
@Test public void installingSdk_then_stillInstalling_doesNotRun() { mockSdkStatusChange(SdkStatus.INSTALLING, SdkStatus.INSTALLING); // mock cancel operation for incomplete install. doReturn(true).when(cloudSdkServiceManager).checkIfCancelled(); cloudSdkServiceManager.runWhenSdkReady(mockProject, mockRunnable, "", mockStatusHandler); ApplicationManager.getApplication().invokeAndWait(() -> verifyNoMoreInteractions(mockRunnable)); }
@Test public void installingSdk_then_userCancel_doesNotShowWarningNotification() { mockSdkStatusChange(SdkStatus.INSTALLING, SdkStatus.INSTALLING); // mock cancel operation for incomplete install. doReturn(true).when(cloudSdkServiceManager).checkIfCancelled(); cloudSdkServiceManager.runWhenSdkReady(mockProject, mockRunnable, "", mockStatusHandler); ApplicationManager.getApplication() .invokeAndWait( () -> // explicit parameters are not relevant but need to be passed for spy to work. verify(cloudSdkServiceManager, never()) .showCloudSdkNotification("", NotificationType.WARNING)); }