@Override public void reset() { if (cloudSdkPanel != null) { cloudSdkPanel.reset(); } }
@Test public void updateNow_notEnabled_whenSdkUpToDate() { ManagedCloudSdkService managedCloudSdkService = mock(ManagedCloudSdkService.class); when(mockCloudSdkServiceManager.getCloudSdkService()).thenReturn(managedCloudSdkService); when(managedCloudSdkService.getStatus()).thenReturn(SdkStatus.READY); when(managedCloudSdkService.isUpToDate()).thenReturn(true); ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings.getInstance() .setUserSelectedSdkServiceType(CloudSdkServiceType.MANAGED_SDK); sdkPanel.reset(); assertThat(sdkPanel.getUpdateNowButton().isEnabled()).isFalse(); }); }
@Test public void updateNow_enabled_whenSdkReadyToUpdate() { ManagedCloudSdkService managedCloudSdkService = mock(ManagedCloudSdkService.class); when(mockCloudSdkServiceManager.getCloudSdkService()).thenReturn(managedCloudSdkService); when(managedCloudSdkService.getStatus()).thenReturn(SdkStatus.READY); when(managedCloudSdkService.isUpToDate()).thenReturn(false); ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings.getInstance() .setUserSelectedSdkServiceType(CloudSdkServiceType.MANAGED_SDK); sdkPanel.reset(); assertThat(sdkPanel.getUpdateNowButton().isEnabled()).isTrue(); }); }
@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 updateNow_notEnabled_whenSdkNotReady() { when(mockCloudSdkService.getStatus()).thenReturn(SdkStatus.INSTALLING); ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings.getInstance() .setUserSelectedSdkServiceType(CloudSdkServiceType.MANAGED_SDK); sdkPanel.reset(); assertThat(sdkPanel.getUpdateNowButton().isEnabled()).isFalse(); }); }
@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 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); } }); }
@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 automaticUpdate_enabled_callsUpdater_activate() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings.getInstance() .setUserSelectedSdkServiceType(CloudSdkServiceType.MANAGED_SDK); CloudSdkServiceUserSettings.getInstance().setEnableAutomaticUpdates(false); sdkPanel.reset(); sdkPanel.getEnableAutomaticUpdatesCheckbox().doClick(); try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } verify(managedCloudSdkUpdateService).activate(); }); }
@Test public void changeSdkType_apply_callsChangedSdkTypeCallback() { ApplicationManager.getApplication() .invokeAndWait( () -> { // use non-spy panel as spy messes up with UI event thread field updates. CloudSdkPanel sdkPanel = new CloudSdkPanel(); CloudSdkServiceUserSettings.getInstance() .setUserSelectedSdkServiceType(CloudSdkServiceType.MANAGED_SDK); sdkPanel.reset(); sdkPanel.getCustomRadioButton().doClick(); String customSdkPath = "/home/gcloud"; sdkPanel.getCloudSdkDirectoryField().setText(customSdkPath); try { sdkPanel.apply(); } catch (ConfigurationException e) { throw new AssertionError(e); } verify(mockCloudSdkServiceManager) .onNewCloudSdkServiceTypeSelected(CloudSdkServiceType.CUSTOM_SDK); }); }
@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 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); }); }