UserServiceImpl implements UserService { @Override @Transactional public User validateProjectManagementRoles(Integer userId) { User user = null; try { if (userId != null) { user = getAndAddPmRole(userId); } userDAO.deletePmWithoutProject(); } catch (ObjectNotUniqueException e) { LOGGER.error("Account already exists", e); } 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 testAddAndcheckProjectManagementRoles() { User user = new User(1); user.setPassword("aa"); user.setSalt(2); user.setUsername("user"); when(userDAO.findById(1)) .thenReturn(user); when(userDAO.persist(user)) .thenReturn(user); userDAO.deletePmWithoutProject(); userService.validateProjectManagementRoles(1); assertEquals("aa", user.getPassword()); }