private void setManagedSdkUiAvailable(boolean available) { if (ServiceManager.getService(PluginInfoService.class).shouldEnable(GctFeature.MANAGED_SDK)) { enableAutomaticUpdatesCheckbox.setEnabled(available); // only make it visible if managed SDK is active, not currently installing or updating, and // not up-to-date. if (available && CloudSdkServiceUserSettings.getInstance().getUserSelectedSdkServiceType() == CloudSdkServiceType.MANAGED_SDK) { ManagedCloudSdkService managedCloudSdkService = (ManagedCloudSdkService) CloudSdkService.getInstance(); updateNowButton.setEnabled( managedCloudSdkService.getStatus() == SdkStatus.READY && !managedCloudSdkService.isUpToDate()); } else { updateNowButton.setEnabled(false); } } }
@Test public void notification_shown_beforeUpdate() { when(mockSdkService.isUpToDate()).thenReturn(false); managedCloudSdkUpdateService.activate(); ApplicationManager.getApplication() .invokeAndWait(() -> verify(mockUiPresenter).notifyManagedSdkUpdate(any(), any())); }
@Test public void update_notCalled_when_sdk_upToDate() { when(mockSdkService.isUpToDate()).thenReturn(true); managedCloudSdkUpdateService.activate(); // managed SDK is UI thread only, ApplicationManager.getApplication() .invokeAndWait(() -> verify(mockSdkService, never()).update()); }
@Test public void update_called_when_sdk_notUpToDate() { when(mockSdkService.isUpToDate()).thenReturn(false); managedCloudSdkUpdateService.activate(); // managed SDK is UI thread only, ApplicationManager.getApplication().invokeAndWait(() -> verify(mockSdkService).update()); }
.shouldEnable(GctFeature.MANAGED_SDK_UPDATE); if (updateFeatureEnabled && !((ManagedCloudSdkService) cloudSdkService).isUpToDate()) {
@Test public void notification_disableUpdates_updatesSettings() { when(mockSdkService.isUpToDate()).thenReturn(false); CloudSdkServiceUserSettings.getInstance().setEnableAutomaticUpdates(true); managedCloudSdkUpdateService.activate(); ApplicationManager.getApplication() .invokeAndWait( () -> { ArgumentCaptor<ActionListener> disableListener = ArgumentCaptor.forClass(ActionListener.class); verify(mockUiPresenter).notifyManagedSdkUpdate(any(), disableListener.capture()); disableListener.getValue().actionPerformed(mock(ActionEvent.class)); assertThat(CloudSdkServiceUserSettings.getInstance().isAutomaticUpdateEnabled()) .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 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(); }); }