@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)); }
@Test public void installingSdk_then_invalidSdk_showsErrorNotification() { mockSdkStatusChange(SdkStatus.INSTALLING, SdkStatus.INVALID); String errorMessage = "Deployment failed: Google Cloud SDK is not ready."; when(mockStatusHandler.getErrorMessage(SdkStatus.INVALID)).thenReturn(errorMessage); cloudSdkServiceManager.runWhenSdkReady(mockProject, mockRunnable, "", mockStatusHandler); ApplicationManager.getApplication() .invokeAndWait( () -> verify(cloudSdkServiceManager) .showCloudSdkNotification(errorMessage, NotificationType.WARNING)); }
@Test public void waitFor_installingSdk_then_invalidSdk_showsErrorNotification() throws InterruptedException { mockSdkStatusChange(SdkStatus.INSTALLING, SdkStatus.INVALID); when(mockStatusHandler.getErrorMessage(SdkStatus.INVALID)) .thenReturn("invalid SDK after waiting"); cloudSdkServiceManager.blockUntilSdkReady(mockProject, "", mockStatusHandler); ApplicationManager.getApplication() .invokeAndWait( () -> verify(cloudSdkServiceManager) .showCloudSdkNotification( "invalid SDK after waiting", NotificationType.WARNING)); }
@Test public void waitFor_when_sdkInstallNotSupported_showsFatalErrorNotification() throws InterruptedException { mockSdkStatusChange(SdkStatus.NOT_AVAILABLE, SdkStatus.NOT_AVAILABLE); when(mockSdkService.isInstallSupported()).thenReturn(false); cloudSdkServiceManager.blockUntilSdkReady(mockProject, "", mockStatusHandler); ApplicationManager.getApplication() .invokeAndWait( () -> verify(cloudSdkServiceManager) .showCloudSdkNotification( CloudSdkMessageBundle.message("managedsdk.not.available"), NotificationType.ERROR)); }
/** Checks the current SDK status after waiting for readiness, notifies and logs about errors. */ private void handleErrors(CloudSdkStatusHandler sdkLogging) { // check the status of SDK after install. SdkStatus postInstallSdkStatus = CloudSdkService.getInstance().getStatus(); switch (postInstallSdkStatus) { case READY: // can continue without logging anything. break; case INSTALLING: // still installing, do nothing, up to caller to decide which message to show. break; case NOT_AVAILABLE: case INVALID: String message; NotificationType notificationType; boolean fatalSdkError = !CloudSdkService.getInstance().isInstallSupported(); if (fatalSdkError) { message = CloudSdkMessageBundle.message("managedsdk.not.available"); notificationType = NotificationType.ERROR; } else { message = sdkLogging.getErrorMessage(postInstallSdkStatus); notificationType = NotificationType.WARNING; } sdkLogging.onError(message); showCloudSdkNotification(message, notificationType); break; default: // do nothing, no error, not ready. } }