SecurityManagementUtils { public static Set<String> rolesToString(final Set<Role> roles) { if (null != roles && !roles.isEmpty()) { final Set<String> result = new HashSet<String>(roles.size()); for (final Role role : roles) { result.add(role.getName()); } return result; } return new HashSet<String>(); }  static User createUser(final String id); static User createUser(final String id,
                                  final Set<Group> groups); static User createUser(final String id,
                                  final Set<Group> groups,
                                  final Set<Role> roles); static User createUser(final String id,
                                  final Set<Group> groups,
                                  final Set<Role> roles,
                                  final Map<String, String> properties); static Group createGroup(final String name); static Role createRole(final String name); static User clone(final User user); static Set<Group> getGroups(final UserSystemManager userSystemManager,
                                       final String username); static Set<Role> getRoles(final UserSystemManager userSystemManager,
                                     final String username); static Set<Role> getRegisteredRoles(); static Set<String> getRegisteredRoleNames(); static void populateGroupOrRoles(final String name,
                                            final Set<String> registeredRoles,
                                            final Set<Group> groups,
                                            final Set<Role> roles); static Set<String> rolesToString(final Set<Role> roles); static Set<String> groupsToString(final Set<Group> groups); static final Capability[] USERS_CAPABILITIES; static final Capability[] GROUPS_CAPABILITIES; static final Capability[] ROLES_CAPABILITIES; }
@Test public void testRolesToString() { Set<Role> roles = new HashSet<Role>(2); Role role1 = mock(Role.class); when(role1.getName()).thenReturn("role1"); Role role2 = mock(Role.class); when(role2.getName()).thenReturn("role2"); roles.add(role1); roles.add(role2); final Set<String> rolesStr = SecurityManagementUtils.rolesToString(roles); assertNotNull(rolesStr); assertTrue(rolesStr.size() == 2); assertTrue(rolesStr.contains("role1")); assertTrue(rolesStr.contains("role2")); }
@Test public void testRolesToStringEmpty() { final Set<String> rolesStr = SecurityManagementUtils.rolesToString(null); assertNotNull(rolesStr); assertTrue(rolesStr.size() == 0); }