@Test public void testCheckSdk_validSdk() { when(cloudSdkValidator.isValidCloudSdk("/non/empty/path")).thenReturn(true); setValidateCloudSdkResponse(); panel.checkSdk("/non/empty/path"); verify(panel, times(0)).showWarning(any(String.class)); verify(panel, times(1)).hideWarning(); }
@Test public void managedSdk_choice_disableAutomaticUpdates_apply_validSettings() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); sdkPanel.reset(); sdkPanel.getManagedRadioButton().doClick(); sdkPanel.getEnableAutomaticUpdatesCheckbox().setSelected(false); try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } verifyCloudSdkSettings( CloudSdkServiceType.MANAGED_SDK, false, /* no auto-updates */ null /* no custom path */); }); }
@Test public void defaultSdkSettings_reset_validUiState() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); // use built-in defaults. sdkPanel.reset(); verifySdkPanelStateForCurrentSettings(sdkPanel); }); }
@Test public void managedSdk_choice_apply_validSettings() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); sdkPanel.reset(); sdkPanel.getManagedRadioButton().doClick(); try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } verifyCloudSdkSettings( CloudSdkServiceType.MANAGED_SDK, CloudSdkServiceUserSettings.DEFAULT_MANAGED_SDK_AUTOMATIC_UPDATES, null /* no custom path */); }); }
@Test public void customSdkSettings_reset_validUiState() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings userSettings = CloudSdkServiceUserSettings.getInstance(); userSettings.setUserSelectedSdkServiceType(CloudSdkServiceType.CUSTOM_SDK); userSettings.setCustomSdkPath("/home/gcloud"); sdkPanel.reset(); verifySdkPanelStateForCurrentSettings(sdkPanel); }); }
@Test public void testCheckSdk_invalidSdk() { setValidateCloudSdkResponse(CloudSdkValidationResult.CLOUD_SDK_NOT_FOUND); when(cloudSdkValidator.isValidCloudSdk("/non/empty/path")).thenReturn(false); panel.checkSdk("/non/empty/path"); verify(panel, times(1)).showWarning(eq(INVALID_SDK_DIR_WARNING)); verify(panel, times(0)).hideWarning(); }
@Test public void customSdk_choice_apply_validSettings() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); sdkPanel.reset(); sdkPanel.getCustomRadioButton().doClick(); String customSdkPath = "/home/gcloud"; sdkPanel.getCloudSdkDirectoryField().setText(customSdkPath); try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } verifyCloudSdkSettings( CloudSdkServiceType.CUSTOM_SDK, CloudSdkServiceUserSettings.DEFAULT_MANAGED_SDK_AUTOMATIC_UPDATES, customSdkPath); }); }
@Test public void testCheckSdk_unsupportedSdk() { setValidateCloudSdkResponse(CloudSdkValidationResult.CLOUD_SDK_NOT_MINIMUM_VERSION); when(cloudSdkValidator.isValidCloudSdk("/non/empty/path")).thenReturn(false); panel.checkSdk("/non/empty/path"); verify(panel, times(1)) .showWarning(eq(CloudSdkValidationResult.CLOUD_SDK_NOT_MINIMUM_VERSION.getMessage())); verify(panel, times(0)).hideWarning(); }
@Test public void testCheckSdk_multipleValidationResults() { setValidateCloudSdkResponse( CloudSdkValidationResult.CLOUD_SDK_NOT_MINIMUM_VERSION, CloudSdkValidationResult.CLOUD_SDK_NOT_FOUND); when(cloudSdkValidator.isValidCloudSdk("/non/empty/path")).thenReturn(false); String expectedMessage = INVALID_SDK_DIR_WARNING + "<p>" + CloudSdkValidationResult.CLOUD_SDK_NOT_MINIMUM_VERSION.getMessage() + "</p>"; panel.checkSdk("/non/empty/path"); verify(panel, times(1)).showWarning(eq(expectedMessage)); verify(panel, times(0)).hideWarning(); }
@Test public void testApplyWith_invalidSdk() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); sdkPanel.reset(); setValidateCloudSdkResponse(CloudSdkValidationResult.CLOUD_SDK_NOT_FOUND); sdkPanel.getCloudSdkDirectoryField().setText("/non/empty/path"); // No exception should be thrown on invalid sdk entry from this panel try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } }); }