### Question:
EcoNewsCommentServiceImpl implements EcoNewsCommentService { @Override @Transactional public void update(String text, Long id, User user) { EcoNewsComment comment = ecoNewsCommentRepo.findById(id) .orElseThrow(() -> new NotFoundException(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION)); if (!user.getId().equals(comment.getUser().getId())) { throw new BadRequestException(ErrorMessage.NOT_A_CURRENT_USER); } comment.setText(text); 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 update() { User user = ModelUtils.getUser(); Long commentId = 1L; String newText = "new text"; when(ecoNewsCommentRepo.findById(commentId)).thenReturn(java.util.Optional.ofNullable(getEcoNewsComment())); ecoNewsCommentService.update(newText, commentId, user); verify(ecoNewsCommentRepo, times(1)).save(any(EcoNewsComment.class)); }
@Test public void updateCommentThatDoesntExistsThrowException() { User user = ModelUtils.getUser(); Long commentId = 1L; String newText = "new text"; when(ecoNewsCommentRepo.findById(commentId)).thenReturn(java.util.Optional.ofNullable(null)); NotFoundException notFoundException = assertThrows(NotFoundException.class, () -> ecoNewsCommentService.update(newText, commentId, user)); assertEquals(ErrorMessage.COMMENT_NOT_FOUND_EXCEPTION, notFoundException.getMessage()); }
@Test public void updateCommentThatDoesntBelongsToUserThrowException() { User user = ModelUtils.getUser(); user.setId(2L); Long commentId = 1L; EcoNewsComment ecoNewsComment = getEcoNewsComment(); ecoNewsComment.setUser(user); String newText = "new text"; when(ecoNewsCommentRepo.findById(commentId)).thenReturn(java.util.Optional.ofNullable(ecoNewsComment)); BadRequestException badRequestException = assertThrows(BadRequestException.class, () -> ecoNewsCommentService.update(newText, commentId, getUser())); assertEquals(ErrorMessage.NOT_A_CURRENT_USER, badRequestException.getMessage()); }