UserAdmin implements UserAdminMBean { public String[] getRequiredMembers(String groupname) throws IOException { if (groupname == null) { throw new IOException("Group name cannot be null"); } Role role = userAdmin.getRole(groupname); if (role != null) { validateRoleType(role, Role.GROUP); Role[] roles = ((Group) role).getRequiredMembers(); if (roles != null) { String[] reqMembers = new String[roles.length]; for (int i = 0; i < roles.length; i++) { reqMembers[i] = roles[i].getName(); } return reqMembers; } } return null; } UserAdmin(org.osgi.service.useradmin.UserAdmin userAdmin); void addCredential(String key, byte[] value, String username); void addCredentialString(String key, String value, String username); boolean addMember(String groupname, String rolename); void addPropertyString(String key, String value, String rolename); void addProperty(String key, byte[] value, String rolename); boolean addRequiredMember(String groupname, String rolename); void createGroup(String name); void createRole(String name); void createUser(String name); CompositeData getAuthorization(String username); TabularData getCredentials(String username); CompositeData getGroup(String groupname); String[] getGroups(String filter); String[] getImpliedRoles(String username); String[] getMembers(String groupname); TabularData getProperties(String rolename); String[] getRequiredMembers(String groupname); CompositeData getRole(String name); String[] getRoles(String filter); CompositeData getUser(String username); String getUserWithProperty(String key, String value); String[] getUsers(String filter); String[] listGroups(); String[] listRoles(); String[] listUsers(); void removeCredential(String key, String username); boolean removeGroup(String name); boolean removeMember(String groupname, String rolename); void removeProperty(String key, String rolename); boolean removeRole(String name); boolean removeUser(String name);  }
@Test public void testGetRequiredMembers() throws IOException { Group group1 = Mockito.mock(Group.class); Mockito.when(group1.getType()).thenReturn(Role.GROUP); Mockito.when(group1.getName()).thenReturn("group1"); User user1 = Mockito.mock(Group.class); Mockito.when(user1.getName()).thenReturn("user1"); Mockito.when(group1.getRequiredMembers()).thenReturn(new Role[] { user1 }); Mockito.when(userAdmin.getRole("group1")).thenReturn(group1); String[] members = mbean.getRequiredMembers("group1"); Assert.assertArrayEquals(new String[] { "user1" }, members); }