UserServiceImpl implements UserService { @Override @Transactional public void persistNewUser(User user, String password) throws ObjectNotUniqueException { User dbUser = userDAO.findByUsername(user.getUsername()); if (dbUser != null && !dbUser.getUserId().equals(user.getUserId())) { throw new ObjectNotUniqueException("Username already in use"); } user.setSalt((int) (Math.random() * 10000)); user.setPassword(encryptPassword(password, user.getSalt())); userDAO.persist(user); projectAssignmentManagementService.assignUserToDefaultProjects(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 shouldCreateNewUser() throws ObjectNotUniqueException { User user = UserObjectMother.createUser(); when(userDAO.findByUsername(user.getUsername())).thenReturn(null); when(userDAO.persist(user)).thenReturn(user); when(assignmentService.assignUserToDefaultProjects(user)).thenReturn(user); userService.persistNewUser(user, "password"); verify(assignmentService).assignUserToDefaultProjects(user); assertNotSame("password", user.getPassword()); }