@Before public void setUp() { // add timer thread to one not to be checked for 'leaks' ThreadTracker.longRunningThreadCreated( ApplicationManager.getApplication(), ManagedCloudSdkUpdateService.SDK_UPDATER_THREAD_NAME); when(mockPluginInfoService.shouldEnable(GctFeature.MANAGED_SDK_UPDATE)).thenReturn(true); when(mockSdkServiceManager.getCloudSdkService()).thenReturn(mockSdkService); ManagedCloudSdkServiceUiPresenter.setInstance(mockUiPresenter); doReturn(mockClock).when(managedCloudSdkUpdateService).getClock(); doReturn(mockUiTimer).when(managedCloudSdkUpdateService).createUiTimer(anyInt()); when(mockUiPresenter.notifyManagedSdkUpdate(any(), any())).thenReturn(mockNotification); // directly execute scheduled tasks. doAnswer( invocationOnMock -> { ((TimerTask) invocationOnMock.getArgument(0)).run(); return null; }) .when(managedCloudSdkUpdateService) .schedule(any(), anyLong(), anyLong()); // directly call task assigned to UI timer. doAnswer( invocationOnMock -> { ((ActionListener) invocationOnMock.getArgument(0)) .actionPerformed(mock(ActionEvent.class)); return null; }) .when(mockUiTimer) .addActionListener(any()); CloudSdkServiceUserSettings.reset(); }
@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(); }