/** Creates managed SDK, installs if necessary, and checks for fatal errors. */ @VisibleForTesting void initManagedSdk() { try { managedCloudSdk = createManagedSdk(); // do not install SDK on activation if user cancelled installation once. if (!CloudSdkServiceUserSettings.getInstance().isUserCancelledInstallation()) { install(); } } catch (UnsupportedOsException ex) { logger.warn("Unsupported OS for Managed Cloud SDK", ex); updateStatus(SdkStatus.NOT_AVAILABLE); ManagedCloudSdkServiceUiPresenter.getInstance() .notifyManagedSdkJobFailure( ManagedSdkJobType.INSTALL, CloudSdkMessageBundle.message("managedsdk.unsupported.os")); } }
@Before public void setUp() throws UnsupportedOsException { // add timer thread to one not to be checked for 'leaks' ThreadTracker.longRunningThreadCreated( ApplicationManager.getApplication(), ManagedCloudSdkUpdateService.SDK_UPDATER_THREAD_NAME); doReturn(mockManagedCloudSdk).when(sdkService).createManagedSdk(); // TODO(ivanporty) remove once test logging system is done via CloudToolsRule sdkService.setLogger(new TestInMemoryLogger()); // make sure everything in test is done synchronously ExecutorService directExecutorService = MoreExecutors.newDirectExecutorService(); ThreadUtil.getInstance().setBackgroundExecutorService(directExecutorService); // run UI updates synchronously doAnswer( invocation -> { ((Runnable) invocation.getArgument(0)).run(); return null; }) .when(sdkService) .invokeOnApplicationUIThread(any()); // replace UI presenter for verifications ManagedCloudSdkServiceUiPresenter.setInstance(mockUiPresenter); when(mockUiPresenter.createProgressListener(any())).thenReturn(mockProgressListener); // init SDK, most tests require initialized state. sdkService.initManagedSdk(); }