public boolean isUpToDate() { try { return managedCloudSdk.isUpToDate(); } catch (Exception e) { // we ignore the exception and just assume SDK is either not up-to-date or in invalid state. return false; } }
/** Mocks out-of-date SDK and update process. */ private void emulateMockSdkUpdateProcess() { try { when(mockManagedCloudSdk.isUpToDate()).thenReturn(false); SdkUpdater mockUpdater = mock(SdkUpdater.class); when(mockManagedCloudSdk.newUpdater()).thenReturn(mockUpdater); } catch (Exception ex) { // shouldn't happen in the tests. throw new AssertionError(ex); } } }
@Test public void upToDate_sdk_passes_valid_jobSuccessResult() throws ManagedSdkVerificationException { makeMockSdkInstalled(MOCK_SDK_PATH); when(mockManagedCloudSdk.isUpToDate()).thenReturn(true); sdkService.update(); verify(mockUiPresenter) .notifyManagedSdkJobSuccess(ManagedSdkJobType.UPDATE, ManagedSdkJobResult.UP_TO_DATE); }
@Test public void testDownloadCloudSdkAction_update() throws ManagedSdkVerificationException, ManagedSdkVersionMismatchException, InterruptedException, CommandExecutionException, SdkInstallerException, IOException, CommandExitException { downloadCloudSdkTask.setManagedCloudSdk(managedCloudSdk); when(managedCloudSdk.isInstalled()).thenReturn(true); when(managedCloudSdk.isUpToDate()).thenReturn(false); downloadCloudSdkTask.downloadCloudSdkAction(); verify(managedCloudSdk, never()).newInstaller(); verify(managedCloudSdk, never()).newComponentInstaller(); verify(managedCloudSdk).newUpdater(); } }
}) .when(mockManagedCloudSdk) .isUpToDate();
if (!managedCloudSdk.isUpToDate()) { SdkUpdater updater = managedCloudSdk.newUpdater(); updater.update(progressListener, consoleListener);
if (!managedCloudSdk.isUpToDate()) { managedCloudSdk.newUpdater().update(progressListener, consoleListener);
private ManagedSdkJobResult updateManagedSdk() throws Exception { if (safeCheckSdkStatus(() -> managedCloudSdk.isInstalled()) && !safeCheckSdkStatus(() -> managedCloudSdk.isUpToDate())) { ConsoleListener sdkUpdateListener = logger::debug; progressListener = ManagedCloudSdkServiceUiPresenter.getInstance().createProgressListener(this); notifySdkProcessingStarted(); executeWithSdkWriteLock( () -> managedCloudSdk.newUpdater().update(progressListener, sdkUpdateListener)); return ManagedSdkJobResult.PROCESSED; } else { return ManagedSdkJobResult.UP_TO_DATE; } }