RoleDTO extends TimestampedCandlepinDTO<RoleDTO> implements RoleInfo { public boolean removeUser(UserDTO user) { if (user == null) { throw new IllegalArgumentException("user is null"); } if (user.getUsername() == null) { throw new IllegalArgumentException("user does not have a valid username"); } return this.removeUser(user.getUsername()); } RoleDTO();  RoleDTO(RoleDTO source); String getId(); RoleDTO setId(String id); String getName(); RoleDTO setName(String name); boolean addUser(UserDTO user); boolean removeUser(UserDTO user); boolean removeUser(String username); Collection<UserDTO> getUsers(); RoleDTO setUsers(Collection<UserDTO> users); boolean addPermission(PermissionBlueprintDTO permission); boolean removePermission(PermissionBlueprintDTO permission); boolean removePermission(String permissionId); Collection<PermissionBlueprintDTO> getPermissions(); RoleDTO setPermissions(Collection<PermissionBlueprintDTO> permissions); @Override String toString(); @Override boolean equals(Object obj); @Override int hashCode(); @Override RoleDTO populate(RoleDTO source); static final long serialVersionUID; }
@Test public void testRemoveUser() { RoleDTO dto = this.getPopulatedDTOInstance(); Collection<UserDTO> users = new LinkedList<>(dto.getUsers()); Collection<UserDTO> removed = new LinkedList<>(); for (UserDTO user : users) { boolean result = dto.removeUser(user); assertTrue(result); removed.add(user); Collection<UserDTO> remaining = dto.getUsers(); assertNotNull(remaining); assertEquals(users.size() - removed.size(), remaining.size()); for (UserDTO existing : users) { assertEquals(!removed.contains(existing), remaining.contains(existing)); } result = dto.removeUser(user); assertFalse(result); remaining = dto.getUsers(); assertNotNull(remaining); assertEquals(users.size() - removed.size(), remaining.size()); for (UserDTO existing : users) { assertEquals(!removed.contains(existing), remaining.contains(existing)); } } }
@Test(expected = IllegalArgumentException.class) public void testRemoveUserNullUser() { RoleDTO dto = this.getDTOInstance(); UserDTO user = null; dto.removeUser(user); }
@Test(expected = IllegalArgumentException.class) public void testRemoveUserIncompleteUser() { RoleDTO dto = this.getDTOInstance(); UserDTO user = new UserDTO(); dto.removeUser(user); }
@Test(expected = IllegalArgumentException.class) public void testRemoveUserByIdNullId() { RoleDTO dto = this.getDTOInstance(); String userId = null; dto.removeUser(userId); }