UserRoleListService { public List<String> doGetRolesForUser( String user ) throws UnauthorizedException { if ( canAdminister() ) { return getRolesForUser( user ); } 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 testDoGetRolesForUser() throws Exception { String user = "TestUser"; doReturn( true ).when( userRoleListService ).canAdminister(); List<String> testRoles = new ArrayList<>(); testRoles.add( "Role_1" ); testRoles.add( "Role_2" ); doReturn( testRoles ).when( userRoleListService ).getRolesForUser( user ); List<String> receivedRoles = userRoleListService.doGetRolesForUser( user ); assertTrue( receivedRoles.size() == 2 ); assertEquals( testRoles.get( 0 ), receivedRoles.get( 0 ) ); assertEquals( testRoles.get( 1 ), receivedRoles.get( 1 ) ); try { doReturn( false ).when( userRoleListService ).canAdminister(); userRoleListService.doGetRolesForUser( user ); } catch ( Exception e ) { assertTrue( e instanceof UserRoleListService.UnauthorizedException ); } }