ProjectAssignmentManagementServiceImpl implements ProjectAssignmentManagementService { @Transactional @Auditable(actionType = AuditActionType.UPDATE) public User assignUserToDefaultProjects(User user) { List<Project> defaultProjects = projectDao.findDefaultProjects(); for (Project project : defaultProjects) { ProjectAssignment assignment = ProjectAssignment.createProjectAssignment(project, user); if (!isAlreadyAssigned(assignment, user.getProjectAssignments())) { LOGGER.debug("Assigning user " + user.getUserId() + " to default project " + project.getName()); user.addProjectAssignment(assignment); persistNewProjectAssignment(assignment); } } return user; } @Autowired  ProjectAssignmentManagementServiceImpl(UserDao userDAO,
                                                  ProjectDao projectDao,
                                                  ProjectAssignmentDao projectAssignmentDao,
                                                  TimesheetDao timesheetDao); @Transactional @Auditable(actionType = AuditActionType.CREATE) void assignAllUsersToProject(Project project); @Override @Transactional @Auditable(actionType = AuditActionType.CREATE) void assignUsersToProjects(List<User> users, ProjectAssignment assignmentTemplate); @Transactional @Auditable(actionType = AuditActionType.UPDATE) ProjectAssignment persistUpdatedProjectAssignment(ProjectAssignment projectAssignment); @Override ProjectAssignment persistNewProjectAssignment(ProjectAssignment assignment); @Transactional @Auditable(actionType = AuditActionType.UPDATE) User assignUserToDefaultProjects(User user); @Transactional @Auditable(actionType = AuditActionType.DELETE) void deleteProjectAssignment(ProjectAssignment assignment);  }
@Test public void should_assign_user_to_default_projects() { Project project = ProjectObjectMother.createProject(1); when(projectDao.findDefaultProjects()).thenReturn(Arrays.asList(project)); User user = UserObjectMother.createUser(); service.assignUserToDefaultProjects(user); verify(projectAssignmentDao).persist(any(ProjectAssignment.class)); }