@Override public String additionalLogoutMessage() { if (stateCollector != null && stateCollector.getBackgroundListeningStates() != null && !stateCollector.getBackgroundListeningStates().isEmpty()) { return GctBundle.message("clouddebug.logout.additional.message"); } else { return ""; } } }
@Override public void run() { for (CloudDebugProcessState state : stateCollector.getBackgroundListeningStates()) { cloudDebugGlobalPoller.pollForChanges(state); } } }
@Test public void testRunCallsPollforChangesForAllStates() throws Exception { List<CloudDebugProcessState> states = new ArrayList<CloudDebugProcessState>(); states.add(mock(CloudDebugProcessState.class)); states.add(mock(CloudDebugProcessState.class)); when(cloudDebugProcessStateCollector.getBackgroundListeningStates()).thenReturn(states); new CloudDebugGlobalPollerTimerTask(cloudDebugGlobalPoller).run(); for (CloudDebugProcessState cloudDebugProcessState : states) { verify(cloudDebugGlobalPoller).pollForChanges(cloudDebugProcessState); } } }
@Test public void testAdditionalLogoutMessage_returnsMessageWhenAStateListens() throws Exception { when(stateCollector.getBackgroundListeningStates()) .thenReturn(Collections.singletonList(mock(CloudDebugProcessState.class))); assertThat(new IntelliJGoogleLoginMessageExtender().additionalLogoutMessage()) .isEqualTo("Any Stackdriver Debug sessions listening in the background will be stopped."); } }
@Test public void testGetBackgroundListeningStates_returnsEmptyListWhenNoProjectIsOpen() { createMockProjectManagerWithProjects(new Project[0]); List<CloudDebugProcessState> backgroundListeningStates = new CloudDebugProcessStateCollector().getBackgroundListeningStates(); assertNotNull(backgroundListeningStates); assertThat(backgroundListeningStates).hasSize(0); }
@Test public void testGetBackgroundListeningStates_withMultipleProjects() { int runningSessions = 1; int listeningSessions = 2; int notListeningSessions = 3; Project project1 = createProject(runningSessions, listeningSessions, notListeningSessions); Project project2 = createProject(runningSessions, listeningSessions, notListeningSessions); createMockProjectManagerWithProjects(new Project[] {project1, project2}); List<CloudDebugProcessState> backgroundListeningStates = new CloudDebugProcessStateCollector().getBackgroundListeningStates(); assertNotNull(backgroundListeningStates); assertThat(backgroundListeningStates).hasSize(2 * listeningSessions); for (CloudDebugProcessState state : backgroundListeningStates) { assertTrue(state.isListenInBackground()); } }