### Question:
EcoNewsCommentServiceImpl implements EcoNewsCommentService { @Override public int countReplies(Long id) { if (!ecoNewsCommentRepo.findById(id).isPresent()) { throw new BadRequestException(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION); } return ecoNewsCommentRepo.countByParentCommentId(id); }  @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 countRepliesCommentThatDoesntExistsThrowException() { Long commentId = 1L; when(ecoNewsCommentRepo.findById(commentId)).thenReturn(java.util.Optional.ofNullable(null)); BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ecoNewsCommentService.countReplies(commentId)); assertEquals(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION, badRequestException.getMessage()); }
@Test public void countReplies() { Long commentId = 1L; EcoNewsComment ecoNewsComment = getEcoNewsComment(); ecoNewsComment.setUsersLiked(new HashSet<>()); when(ecoNewsCommentRepo.findById(commentId)).thenReturn(java.util.Optional.ofNullable(ecoNewsComment)); when(ecoNewsCommentRepo.countByParentCommentId(commentId)).thenReturn(0); assertEquals(0, ecoNewsCommentService.countReplies(commentId)); }