ProjectService { public Project addProject(Project project, UserEntity creator) { Assert.notNull(project); Assert.notNull(creator); ProjectEntity projectEntity = new ProjectEntity(creator, project, currentFinancingRound()); projectEntity = projectRepository.save(projectEntity); notifyAdminsOnNewProject(projectEntity); LOG.debug("Project added: {}", projectEntity); return project(projectEntity, creator); } @Autowired  ProjectService(ProjectRepository projectRepository,
                          PledgeRepository pledgeRepository,
                          UserRepository userRepository,
                          FinancingRoundRepository financingRoundRepository,
                          UserNotificationService userNotificationService,
                          FinancingRoundService financingRoundService,
                          LikeRepository likeRepository,
                          ProjectAttachmentRepository projectAttachmentRepository); Project getProject(String projectId, UserEntity requestingUser); List<Project> getProjects(UserEntity requestingUser); Project addProject(Project project, UserEntity creator); Project modifyProjectStatus(String projectId, ProjectStatus newStatusToApply, UserEntity requestingUser); Project modifyProjectMasterdata(String projectId, Project modifiedProject, UserEntity requestingUser); void pledge(String projectId, UserEntity userEntity, Pledge pledge); Attachment addProjectAttachment(String projectId, Attachment attachment, UserEntity savingUser); Attachment loadProjectAttachment(String projectId, Attachment attachmentRequest); void deleteProjectAttachment(String projectId, Attachment attachmentRequest, UserEntity deletingUser); void likeProject(String projectId, UserEntity user); void unlikeProject(String projectId, UserEntity user);  }
@Test public void addProject() throws Exception { final Project project = project("myTitle", "theFullDescription", "theShortDescription", 50, ProjectStatus.PROPOSED); final ArgumentCaptor<ProjectEntity> projectEntity = ArgumentCaptor.forClass(ProjectEntity.class); when(projectRepository.save(projectEntity.capture())).thenAnswer(a -> a.getArgumentAt(0, ProjectEntity.class)); prepareActiveFinanzingRound(null); Project res = projectService.addProject(project, user(USER_EMAIL)); assertThat(res, is(new Project(projectEntity.getValue(), new ArrayList<>(), null, 0, LIKE))); verify(userNotificationService, atLeastOnce()).notifyAdminOnProjectCreation(eq(projectEntity.getValue()), anyString()); }
@Test public void createProjectTriggersAdminNotification() throws Exception { final Project newProject = new Project(); projectService.addProject(newProject, user("some@mail.com")); verify(userNotificationService).notifyAdminOnProjectCreation(any(ProjectEntity.class), eq(ADMIN1_EMAIL)); verify(userNotificationService).notifyAdminOnProjectCreation(any(ProjectEntity.class), eq(ADMIN2_EMAIL)); verify(userNotificationService, times(2)).notifyAdminOnProjectCreation(any(ProjectEntity.class), anyString()); }