ProjectService { public void likeProject(String projectId, UserEntity user) { final ProjectEntity project = projectRepository.findOne(projectId); toggleStatus(project, user, LIKE); } @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 likeProject_shouldCreateLikeEntityIfNotExists() throws Exception { when(likeRepository.findOneByProjectAndUser(any(ProjectEntity.class), any(UserEntity.class))).thenReturn(Optional.empty()); projectService.likeProject("projectId", any(UserEntity.class)); final ArgumentCaptor<LikeEntity> captor = ArgumentCaptor.forClass(LikeEntity.class); verify(likeRepository, times(1)).findOneByProjectAndUser(any(ProjectEntity.class), any(UserEntity.class)); verify(likeRepository, times(1)).save(captor.capture()); assertThat(captor.getValue().getStatus(), is(LIKE)); }
@Test public void likeProject_shouldCreateLikeEntityIfExists() throws Exception { when(likeRepository.findOneByProjectAndUser(any(ProjectEntity.class), any(UserEntity.class))).thenReturn(Optional.of(new LikeEntity())); projectService.likeProject("projectId", any(UserEntity.class)); final ArgumentCaptor<LikeEntity> captor = ArgumentCaptor.forClass(LikeEntity.class); verify(likeRepository, times(1)).findOneByProjectAndUser(any(ProjectEntity.class), any(UserEntity.class)); verify(likeRepository, times(1)).save(captor.capture()); assertThat(captor.getValue().getStatus(), is(LIKE)); }