ProjectAssignmentManagementServiceImpl implements ProjectAssignmentManagementService { @Override @Transactional @Auditable(actionType = AuditActionType.CREATE) public void assignUsersToProjects(List<User> users, ProjectAssignment assignmentTemplate) { for (User user : users) { ProjectAssignment assignment = ProjectAssignment.createProjectAssignment(assignmentTemplate, user); persistNewProjectAssignment(assignment); } } @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_users_to_project_using_template_assignment() { ProjectAssignment templateAssignment = ProjectAssignmentObjectMother.createProjectAssignment(1); templateAssignment.setAllottedHours(5f); User userA = UserObjectMother.createUser(); userA.setLastName("A"); User userB = UserObjectMother.createUser(); userB.setLastName("B"); userB.setUserId(2); List<User> users = Arrays.asList(userA, userB); service.assignUsersToProjects(users, templateAssignment); ArgumentCaptor<ProjectAssignment> captor = ArgumentCaptor.forClass(ProjectAssignment.class); verify(projectAssignmentDao, times(2)).persist(captor.capture()); List<ProjectAssignment> assignments = captor.getAllValues(); ProjectAssignment assignment = assignments.get(0); assertEquals(userA, assignment.getUser()); assertEquals(5f, assignment.getAllottedHours(), 0); }