/** * Prepares common test case with test user (active) and its one test project. * * @param selectedProject Project to set as selected for the dialog, may be null/empty. */ private void prepareOneTestUserOneTestProjectDialog(CloudProject selectedProject) { mockUserList(Collections.singletonList(mockTestUser)); mockUserProjects(mockTestUser, Collections.singletonList(testGoogleProject)); cleanLoadUsersAndProjects(); projectSelectionDialog.setSelectedProject(selectedProject); }
@Test public void addActiveAccount_withNoProjects_clearsProjectList() { prepareOneTestUserOneTestProjectDialog(testUiProject); String activeUserEmail = "active-test@google.com"; CredentialedUser mockAnotherUser = mock(CredentialedUser.class); when(mockAnotherUser.getEmail()).thenReturn(activeUserEmail); mockUserList(Arrays.asList(mockAnotherUser /* active */, mockTestUser)); mockUserProjects(mockAnotherUser, Collections.emptyList()); cleanLoadUsersAndProjects(); assertThat(projectSelectionDialog.getAccountComboBox().getSelectedItem()) .isEqualTo(mockAnotherUser); assertThat(projectSelectionDialog.getProjectListTableModel().getRowCount()).isEqualTo(0); assertThat(projectSelectionDialog.getProjectListTable().getSelectedRow()).isEqualTo(-1); }