@Test void updateTest() { TipsAndTricksComment tipsAndTricksComment = ModelUtils.getTipsAndTricksComment(); when(tipsAndTricksCommentRepo.findById(anyLong())).thenReturn(Optional.of(tipsAndTricksComment)); when(tipsAndTricksCommentRepo.save(tipsAndTricksComment)).thenReturn(tipsAndTricksComment); tipsAndTricksCommentService.update("new text", 1L, ModelUtils.getUser()); assertEquals("new text", tipsAndTricksComment.getText()); }
@Override public void update(String text, Long id, User user) { TipsAndTricksComment comment = tipsAndTricksCommentRepo.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); tipsAndTricksCommentRepo.save(comment); }
TipsAndTricksCommentServiceImpl implements TipsAndTricksCommentService { @Override public void update(String text, Long id, User user) { TipsAndTricksComment comment = tipsAndTricksCommentRepo.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); tipsAndTricksCommentRepo.save(comment); } }
TipsAndTricksCommentServiceImpl implements TipsAndTricksCommentService { @Override public void update(String text, Long id, User user) { TipsAndTricksComment comment = tipsAndTricksCommentRepo.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); tipsAndTricksCommentRepo.save(comment); }  }
TipsAndTricksCommentServiceImpl implements TipsAndTricksCommentService { @Override public void update(String text, Long id, User user) { TipsAndTricksComment comment = tipsAndTricksCommentRepo.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); tipsAndTricksCommentRepo.save(comment); }  @Override AddTipsAndTricksCommentDtoResponse save(Long tipsandtricksId,
                                                   AddTipsAndTricksCommentDtoRequest addTipsAndTricksCommentDtoRequest,
                                                   User user); @Override PageableDto<TipsAndTricksCommentDto> findAllComments(Pageable pageable, User user, Long tipsAndTricksId); @Override List<TipsAndTricksCommentDto> findAllReplies(Long parentCommentId); @Override void deleteById(Long id, User user); @Override void update(String text, Long id, User user); @Override void like(Long id, User user); @Override int countLikes(Long id); @Override int countReplies(Long id); @Override int countComments(Long tipAndTricksId); }
TipsAndTricksCommentServiceImpl implements TipsAndTricksCommentService { @Override public void update(String text, Long id, User user) { TipsAndTricksComment comment = tipsAndTricksCommentRepo.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); tipsAndTricksCommentRepo.save(comment); }  @Override AddTipsAndTricksCommentDtoResponse save(Long tipsandtricksId,
                                                   AddTipsAndTricksCommentDtoRequest addTipsAndTricksCommentDtoRequest,
                                                   User user); @Override PageableDto<TipsAndTricksCommentDto> findAllComments(Pageable pageable, User user, Long tipsAndTricksId); @Override List<TipsAndTricksCommentDto> findAllReplies(Long parentCommentId); @Override void deleteById(Long id, User user); @Override void update(String text, Long id, User user); @Override void like(Long id, User user); @Override int countLikes(Long id); @Override int countReplies(Long id); @Override int countComments(Long tipAndTricksId);  }