RoleServiceImpl extends WaspServiceImpl implements RoleService { @Override public List<String> getUniqueSortedRoleList(User user){ Set<String> rolesAsSet = new HashSet<String>(); List<Userrole> userroles = user.getUserrole(); for(Userrole userrole : userroles){ rolesAsSet.add(userrole.getRole().getName()); } List<LabUser> labUsers = user.getLabUser(); for(LabUser labUser : labUsers){ rolesAsSet.add(labUser.getRole().getName()); } Map<String, Integer> departmentuserQueryMap = new HashMap<String, Integer>(); departmentuserQueryMap.put("userId", user.getId()); List<DepartmentUser> departmentUsers = departmentUserDao.findByMap(departmentuserQueryMap); if(departmentUsers.size() > 0){ rolesAsSet.add("Dep't. Admin."); } List<String> roles = new ArrayList<String>(rolesAsSet); Collections.sort(roles); return roles; }  void setDepartmentUserDao(DepartmentUserDao departmentUserDao); @Override //SuperUser, Facility Manager, Facility Tech, System Admin, Facility Admin, PI, Lab Manager, Lab Member, Department Admin. List<String> getUniqueSortedRoleList(User user); @Override //SuperUser, Facility Manager, Facility Tech, System Admin, Facility Admin, PI (with lab name as PI's last name), Lab Manager (with PI's last name), Lab Member (with PI's last name), Department Admin (departments NOT listed as could be long list). List<String> getCompleteSortedRoleList(User user); @Override List<Role> convertMetaRoleVisibilityDelimitedStringToRoleList(String roleVisibility); @Override Role getRoleByRolename(String roleName); @Override String convertRoleListToMetaRoleVisibilityDelimitedString(List<Role> roleList); @Override boolean metaRoleVisibilityDelimitedStringContainsRole(String roleVisibility, Role role); @Override String addRoleToMetaRoleVisibility(String roleVisibility, Role role); @Override String removeRoleFromMetaRoleVisibility(String roleVisibility, Role role);  }
@Test (groups = "unit-tests-service-objects") public void getUniqueSortedRoleList() { User user = new User(); Userrole userrole = new Userrole(); List<Userrole> userroles = new ArrayList<Userrole>(); List<LabUser> labUsers = new ArrayList<LabUser>(); LabUser labUser = new LabUser(); Role role1 = new Role(); role1.setId(1); role1.setName("Facility Manager"); userrole.setRole(role1); userroles.add(userrole); Role role2 = new Role(); role2.setId(2); role2.setName("PI"); labUser.setRole(role2); labUsers.add(labUser); user.setUserrole(userroles); user.setLabUser(labUsers); Map<String, Integer> departmentuserQueryMap = new HashMap<String, Integer>(); departmentuserQueryMap.put("userId", null); List<DepartmentUser> departmentUsers = new ArrayList<DepartmentUser>(); List<String> roles = new ArrayList<String>(); roles.add("Facility Manager"); roles.add("PI"); roleServiceImpl.setDepartmentUserDao(mockDepartmentUserDao); expect(mockDepartmentUserDao.findByMap(departmentuserQueryMap)).andReturn(departmentUsers); replay(mockDepartmentUserDao); Assert.assertEquals(roles, roleServiceImpl.getUniqueSortedRoleList(user)); verify(mockDepartmentUserDao); }