UserRoleListService { public RoleListWrapper getPermissionRoles( String adminRole ) { IUserRoleListService userRoleListService = getUserRoleListService(); List<String> allRoles = userRoleListService.getAllRoles(); if ( allRoles.contains( adminRole ) ) { allRoles.remove( adminRole ); } if ( extraRoles != null ) { for ( String extraRole : extraRoles ) { if ( !allRoles.contains( extraRole ) ) { allRoles.add( extraRole ); } } } if ( null != roleComparator ) { Collections.sort( allRoles, roleComparator ); } return new RoleListWrapper( allRoles ); }  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 testGetPermissionRoles() { List<String> roles = new ArrayList<String>(); roles.add( "ROLE1" ); roles.add( "ROLE2" ); roles.add( "ADMIN_ROLE" ); IUserRoleListService userRoleListService1 = mock( IUserRoleListService.class ); doReturn( userRoleListService1 ).when( userRoleListService ).getUserRoleListService(); doReturn( roles ).when( userRoleListService1 ).getAllRoles(); ArrayList<String> extraRoles = new ArrayList<String>(); extraRoles.add( "EXTRA_ROLE1" ); extraRoles.add( "EXTRA_ROLE2" ); userRoleListService.setExtraRoles( extraRoles ); RoleListWrapper roleWrapper = userRoleListService.getPermissionRoles( "ADMIN_ROLE" ); assertTrue( !roleWrapper.getRoles().contains( "ADMIN_ROLE" ) ); assertTrue( roleWrapper.getRoles().size() == 4 ); }