@Test public void getPrimaryGroupUserIDsWhenNoMembersReturnsEmptyList() throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException { when(sql.sqlQuery(anyString())).thenReturn(result); when(result.next()).thenReturn(false); assertEquals(0, webGroupDao.getUserIDsFromPrimaryGroup(group1).size()); }
@Test public void getPrimaryGroupUserIDsReturnsUserID() throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException { when(sql.sqlQuery(anyString())).thenReturn(result); when(result.next()).thenReturn(true, false); when(result.getString(configuration.webappPrimaryGroupUserIDColumn)).thenReturn(user_id1); List<String> groupMembers = webGroupDao.getUserIDsFromPrimaryGroup(group1); assertEquals(1, groupMembers.size()); assertEquals(user_id1, groupMembers.get(0)); }
@Test public void getPrimaryGroupUserIDsWithMultipleUserIDsReturnUserIDs() throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException { String userID2 = RandomStringUtils.randomNumeric(2); when(sql.sqlQuery(anyString())).thenReturn(result); when(result.next()).thenReturn(true, true, false); when(result.getString(configuration.webappPrimaryGroupUserIDColumn)) .thenReturn(user_id1, userID2); List<String> groupMembers = webGroupDao.getUserIDsFromPrimaryGroup(group1); assertEquals(2, groupMembers.size()); assertEquals(user_id1, groupMembers.get(0)); assertEquals(userID2, groupMembers.get(1)); }
@Test public void getPrimaryGroupUserIDsWhenPrimaryDisabledReturnsEmptyList() throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException { configuration.webappPrimaryGroupEnabled = false; assertEquals(0, webGroupDao.getUserIDsFromPrimaryGroup(group1).size()); }
@Test public void getPrimaryGroupUserIDsNeverReturnNull() throws IllegalAccessException, InstantiationException, MalformedURLException, SQLException { configuration.webappPrimaryGroupEnabled = false; assertNotNull(webGroupDao.getUserIDsFromPrimaryGroup(group1)); }