UserRoleListService { public List<String> doGetUsersInRole( String role ) throws UnauthorizedException { if ( canAdminister() ) { return getUsersInRole( role ); } else { throw new UnauthorizedException(); } }  List<String> doGetRolesForUser( String user ); List<String> doGetUsersInRole( String role ); UserListWrapper getUsers(); RoleListWrapper getRoles(); RoleListWrapper getRoles( boolean includeExtraRoles ); RoleListWrapper getAllRoles(); RoleListWrapper getSystemRoles(); RoleListWrapper getPermissionRoles( String adminRole ); RoleListWrapper getExtraRolesList(); IUserRoleListService getUserRoleListService(); void setExtraRoles( ArrayList<String> extraRoles ); void setSystemRoles( ArrayList<String> systemRoles ); void setRoleComparator( Comparator<String> roleComparator ); void setUserComparator( Comparator<String> userComparator ); ArrayList<String> getExtraRoles();  }
@Test public void testDoGetUsersInRole() throws Exception { String role = "TestRole"; doReturn( true ).when( userRoleListService ).canAdminister(); List<String> testUsers = new ArrayList<>(); testUsers.add( "User_1" ); testUsers.add( "User_2" ); doReturn( testUsers ).when( userRoleListService ).getUsersInRole( role ); List<String> receivedUsers = userRoleListService.getUsersInRole( role ); assertTrue( receivedUsers.size() == 2 ); assertEquals( testUsers.get( 0 ), receivedUsers.get( 0 ) ); assertEquals( testUsers.get( 1 ), receivedUsers.get( 1 ) ); try { doReturn( false ).when( userRoleListService ).canAdminister(); userRoleListService.doGetUsersInRole( role ); } catch ( Exception e ) { assertTrue( e instanceof UserRoleListService.UnauthorizedException ); } }