@Before public void setUp() { when(mockCloudSdkServiceManager.getCloudSdkService()).thenReturn(mockSdkService); // empty error messages by default when(mockStatusHandler.getErrorMessage(any())).thenReturn(""); }
@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)); }
/** 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. } }