UserServiceImpl implements UserService { @Transactional(readOnly = true) public User getUser(Integer userId) throws ObjectNotFoundException { User user = userDAO.findById(userId); Set<ProjectAssignment> inactiveAssignments = new HashSet<>(); if (user != null && user.getProjectAssignments() != null) { splitActiveAndInactiveAssignments(user, inactiveAssignments); } else { throw new ObjectNotFoundException("User not found"); } return user; }  @Transactional(readOnly = true) User getUser(Integer userId); @Transactional(readOnly = true) User getUserAndCheckDeletability(Integer userId); @Transactional(readOnly = true) User getUser(String username); @Transactional(readOnly = true) List<UserDepartment> getUserDepartments(); @Transactional UserDepartment persistUserDepartment(UserDepartment department); @Transactional(readOnly = true) UserDepartment getUserDepartment(Integer departmentId); @Transactional(readOnly = true) List<User> getUsers(); @Transactional(readOnly = true) List<User> getActiveUsers(); @Transactional(readOnly = true) List<UserRole> getUserRoles(); @Transactional User persistEditedUser(User user); @Override @Transactional void persistNewUser(User user, String password); @Override @Transactional void changePassword(String username, String currentPassword, String newUnencryptedPassword); @Override @Transactional void changePassword(String username, String newUnencryptedPassword); List<User> getUsersWithEmailSet(); @Override @Transactional User validateProjectManagementRoles(Integer userId); @Override @Transactional(readOnly = true) List<User> getUsers(UserRole userRole); @Transactional void deleteUser(Integer userId); @Transactional void deleteDepartment(Integer departmentId); void setPasswordEncoder(MessageDigestPasswordEncoder passwordEncoder); void setProjectAssignmentManagementService(ProjectAssignmentManagementService projectAssignmentManagementService); void setUserDAO(UserDao dao); void setUserDepartmentDAO(UserDepartmentDao dao); void setUserRoleDAO(UserRoleDao dao);  }
@Test public void testGetUser() throws ObjectNotFoundException { User user; ProjectAssignment assignmentA, assignmentB; Project projectA, projectB; Set<ProjectAssignment> assignments = new HashSet<>(); Calendar calA, calB; user = new User("thies", "pwd"); projectA = new Project(); projectA.setActive(true); assignmentA = new ProjectAssignment(); assignmentA.setAssignmentId(1); assignmentA.setAssignmentType(new ProjectAssignmentType(0)); calA = new GregorianCalendar(); calA.add(Calendar.MONTH, -5); assignmentA.setDateStart(calA.getTime()); calA.add(Calendar.MONTH, 1); assignmentA.setDateEnd(calA.getTime()); assignmentA.setProject(projectA); assignments.add(assignmentA); projectB = new Project(); projectB.setActive(true); assignmentB = new ProjectAssignment(); assignmentB.setAssignmentId(2); assignmentB.setAssignmentType(new ProjectAssignmentType(0)); calB = new GregorianCalendar(); calB.add(Calendar.MONTH, -2); assignmentB.setDateStart(calB.getTime()); calB = new GregorianCalendar(); calB.add(Calendar.MONTH, 1); assignmentB.setDateEnd(calB.getTime()); assignmentB.setProject(projectB); assignments.add(assignmentB); user.setProjectAssignments(assignments); when(userDAO.findById(1)) .thenReturn(user); user = userService.getUser(1); verify(userDAO).findById(1); assertEquals("thies", user.getUsername()); assertEquals(1, user.getProjectAssignments().size()); assertEquals(1, user.getInactiveProjectAssignments().size()); }