### Question:
TransactionalPostCommentService extends
        AbstractTransactionalEntityService<PostComment, Crud<PostComment>> implements
        PostCommentService, PluginCommentService { public PostComment updateComment(long id, String body, long branchId) throws NotFoundException { PostComment comment = get(id); checkHasUpdatePermission(comment, branchId); comment.setBody(body); comment.setUserChanged(userService.getCurrentUser()); comment.setModificationDate(DateTime.now()); getDao().saveOrUpdate(comment); return comment; } TransactionalPostCommentService(Crud<PostComment> dao,
                                           PermissionService permissionService, UserService userService); PostComment updateComment(long id, String body, long branchId); @Override PostComment getComment(long id); @Override @PreAuthorize("(hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OWN_POSTS') and " + "#comment.author.username == principal.username) or " + "(hasPermission(#post.topic.branch.id, 'BRANCH', 'BranchPermission.DELETE_OTHERS_POSTS') and " + "#comment.author.username != principal.username)") PostComment markCommentAsDeleted(Post post, PostComment comment);  }### Answer:
@Test public void testUpdateCommentSuccess() throws Exception { givenUserHasPermissionToEditOwnPosts(true); PostComment comment = postCommentService.updateComment(CR_ID, COMMENT_BODY, BRANCH_ID); assertEquals(comment.getBody(), COMMENT_BODY); }
@Test(expectedExceptions = NotFoundException.class) public void testUpdateCommentNotFound() throws Exception { postCommentService.updateComment(123L, null, BRANCH_ID); }
@Test public void testUpdateCommentNotOwnerButHasEditOthersPermission() throws NotFoundException { givenCurrentUser("not-the-author-of-comment"); givenUserHasPermissionToEditOwnPosts(false); givenUserHasPermissionToEditOthersPosts(true); PostComment comment = postCommentService.updateComment(CR_ID, COMMENT_BODY, BRANCH_ID); assertEquals(comment.getBody(), COMMENT_BODY); }
@Test public void testSubscriberNotGetNotificationAboutEditingComment() throws Exception { postCommentService.updateComment(CR_ID, COMMENT_BODY + "updated", BRANCH_ID); verifyZeroInteractions(notificationService); }
@Test(expectedExceptions = AccessDeniedException.class) public void testUpdateCommentNoBothPermission() throws NotFoundException { givenUserHasPermissionToEditOwnPosts(false); givenUserHasPermissionToEditOthersPosts(false); postCommentService.updateComment(CR_ID, null, BRANCH_ID); }
@Test(expectedExceptions = AccessDeniedException.class) public void testUpdateCommentNoEditOwnPermission() throws NotFoundException { givenUserHasPermissionToEditOwnPosts(false); givenUserHasPermissionToEditOthersPosts(true); postCommentService.updateComment(CR_ID, null, BRANCH_ID); }
@Test(expectedExceptions = AccessDeniedException.class) public void testUpdateCommentNotOwnerNoEditOthersPermission() throws NotFoundException { givenCurrentUser("not-the-author-of-comment"); givenUserHasPermissionToEditOthersPosts(false); givenUserHasPermissionToEditOwnPosts(true); postCommentService.updateComment(CR_ID, null, BRANCH_ID); }