@Test public void notification_shown_beforeUpdate() { when(mockSdkService.isUpToDate()).thenReturn(false); managedCloudSdkUpdateService.activate(); ApplicationManager.getApplication() .invokeAndWait(() -> verify(mockUiPresenter).notifyManagedSdkUpdate(any(), any())); }
Notification updateNotification = ManagedCloudSdkServiceUiPresenter.getInstance() .notifyManagedSdkUpdate(cancelListener, disableUpdateListener);
@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(); }); } }
@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(); }