TomcatUserManager extends BaseTomcatManager implements UserManager,
                                                                    ContextualManager { @Override public void assignRoles(String username, Collection<String> roles) throws SecurityManagementException { Set<String> userGroups = SecurityManagementUtils.groupsToString(SecurityManagementUtils.getGroups(userSystemManager, username)); userGroups.addAll(roles); doAssignGroups(username, userGroups); } TomcatUserManager();  TomcatUserManager(final Map<String, String> gitPrefs);  TomcatUserManager(final ConfigProperties gitPrefs); @Override void initialize(final UserSystemManager userSystemManager); @Override void destroy(); @Override SearchResponse<User> search(SearchRequest request); @Override User get(String identifier); @Override List<User> getAll(); @Override User create(User entity); @Override User update(User entity); @Override void delete(String... identifiers); @Override UserManagerSettings getSettings(); @Override void assignGroups(String username,
                             Collection<String> groups); @Override void assignRoles(String username,
                            Collection<String> roles); @Override void changePassword(String username,
                               String newPassword);  }
@Test public void testAssignRoles() { RoleRegistry.get().registerRole("role1"); RoleRegistry.get().registerRole("role3"); final User user = mock(User.class); when(user.getIdentifier()).thenReturn("user1"); when(user.getGroups()).thenReturn(new HashSet<Group>()); UserManager userManagerMock = mock(UserManager.class); doAnswer(new Answer<User>() { @Override public User answer(InvocationOnMock invocationOnMock) throws Throwable { return user; } }).when(userManagerMock).get("user1"); when(userSystemManager.users()).thenReturn(userManagerMock); Collection<String> roles = new ArrayList<String>(); roles.add("role1"); roles.add("role3"); usersManager.assignRoles("user1", roles); Set<Role> result = usersManager.get("user1").getRoles(); assertNotNull(result); assertEquals(2, result.size()); }