### Question:
EcoNewsCommentServiceImpl implements EcoNewsCommentService { public void like(Long id, User user) { EcoNewsComment comment = ecoNewsCommentRepo.findById(id) .orElseThrow(() -> new NotFoundException(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION)); if (comment.getUsersLiked().contains(user)) { comment.getUsersLiked().remove(user); } else { comment.getUsersLiked().add(user); } ecoNewsCommentRepo.save(comment); }  @Override AddEcoNewsCommentDtoResponse save(Long econewsId, AddEcoNewsCommentDtoRequest addEcoNewsCommentDtoRequest,
                                             User user); @Override PageableDto<EcoNewsCommentDto> findAllComments(Pageable pageable, User user, Long ecoNewsId); @Override PageableDto<EcoNewsCommentDto> findAllReplies(Pageable pageable, Long parentCommentId, User user); @Override void deleteById(Long id, User user); @Override @Transactional void update(String text, Long id, User user); void like(Long id, User user); @Override @Transactional int countLikes(Long id); @Override int countReplies(Long id); @Override int countOfComments(Long ecoNewsId); @Override PageableDto<EcoNewsCommentDto> getAllActiveComments(Pageable pageable, User user, Long ecoNewsId);  }### Answer:
@Test public void like() { Long commentId = 1L; EcoNewsComment ecoNewsComment = getEcoNewsComment(); ecoNewsComment.setUsersLiked(new HashSet<>()); when(ecoNewsCommentRepo.findById(commentId)).thenReturn(java.util.Optional.ofNullable(ecoNewsComment)); ecoNewsCommentService.like(commentId, getUser()); verify(ecoNewsCommentRepo).save(any(EcoNewsComment.class)); assertEquals(1, ecoNewsComment.getUsersLiked().size()); }
@Test public void likeCommentThatDoesntExistThrowException() { Long commentId = 1L; when(ecoNewsCommentRepo.findById(commentId)).thenReturn(java.util.Optional.ofNullable(null)); NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> ecoNewsCommentService.like(commentId, getUser())); assertEquals(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION, notFoundException.getMessage()); }