@Test public void countLikesCommentThatDoesntExistsThrowException() { Long commentId = 1L; when(ecoNewsCommentRepo.findById(commentId)).thenReturn(java.util.Optional.ofNullable(null)); BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ecoNewsCommentService.countLikes(commentId)); assertEquals(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION, badRequestException.getMessage()); }
@Override @Transactional public int countLikes(Long id) { EcoNewsComment comment = ecoNewsCommentRepo.findById(id).orElseThrow( () -> new BadRequestException(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION) ); return comment.getUsersLiked().size(); }
EcoNewsCommentServiceImpl implements EcoNewsCommentService { @Override @Transactional public int countLikes(Long id) { EcoNewsComment comment = ecoNewsCommentRepo.findById(id).orElseThrow( () -> new BadRequestException(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION) ); return comment.getUsersLiked().size(); } }
EcoNewsCommentServiceImpl implements EcoNewsCommentService { @Override @Transactional public int countLikes(Long id) { EcoNewsComment comment = ecoNewsCommentRepo.findById(id).orElseThrow( () -> new BadRequestException(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION) ); return comment.getUsersLiked().size(); }  }
EcoNewsCommentServiceImpl implements EcoNewsCommentService { @Override @Transactional public int countLikes(Long id) { EcoNewsComment comment = ecoNewsCommentRepo.findById(id).orElseThrow( () -> new BadRequestException(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION) ); return comment.getUsersLiked().size(); }  @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); }
EcoNewsCommentServiceImpl implements EcoNewsCommentService { @Override @Transactional public int countLikes(Long id) { EcoNewsComment comment = ecoNewsCommentRepo.findById(id).orElseThrow( () -> new BadRequestException(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION) ); return comment.getUsersLiked().size(); }  @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);  }