MBCommentManagerImpl implements CommentManager { @Override public long addComment( long userId, long groupId, String className, long classPK, String body, Function<String, ServiceContext> serviceContextFunction) throws PortalException { MBMessageDisplay messageDisplay = _mbMessageLocalService.getDiscussionMessageDisplay( userId, groupId, className, classPK, WorkflowConstants.STATUS_APPROVED); MBThread thread = messageDisplay.getThread(); List<MBMessage> messages = _mbMessageLocalService.getThreadMessages( thread.getThreadId(), WorkflowConstants.STATUS_APPROVED); for (MBMessage message : messages) { String messageBody = message.getBody(); if (messageBody.equals(body)) { throw new DuplicateCommentException(body); } } ServiceContext serviceContext = serviceContextFunction.apply( MBMessage.class.getName()); MBMessage mbMessage = _mbMessageLocalService.addDiscussionMessage( userId, StringPool.BLANK, groupId, className, classPK, thread.getThreadId(), thread.getRootMessageId(), StringPool.BLANK, body, serviceContext); return mbMessage.getMessageId(); }  @Override long addComment(
			long userId, long groupId, String className, long classPK,
			String body,
			Function<String, ServiceContext> serviceContextFunction); @Override long addComment(
			long userId, long groupId, String className, long classPK,
			String userName, String subject, String body,
			Function<String, ServiceContext> serviceContextFunction); @Override long addComment(
			long userId, String className, long classPK, String userName,
			long parentCommentId, String subject, String body,
			Function<String, ServiceContext> serviceContextFunction); @Override void addDiscussion(
			long userId, long groupId, String className, long classPK,
			String userName); @Override Discussion copyDiscussion(
			long userId, long groupId, String className, long classPK,
			long newClassPK,
			Function<String, ServiceContext> serviceContextFunction); @Override void deleteComment(long commentId); @Override void deleteDiscussion(String className, long classPK); @Override void deleteGroupComments(long groupId); @Override Comment fetchComment(long commentId); @Override DiscussionComment fetchDiscussionComment(long userId, long commentId); @Override List<Comment> getChildComments(
		long parentCommentId, int status, int start, int end); @Override int getChildCommentsCount(long parentCommentId, int status); @Override int getCommentsCount(String className, long classPK); @Override Discussion getDiscussion(
			long userId, long groupId, String className, long classPK,
			Function<String, ServiceContext> serviceContextFunction); @Override DiscussionPermission getDiscussionPermission(
		PermissionChecker permissionChecker); @Override DiscussionStagingHandler getDiscussionStagingHandler(); @Override List<Comment> getRootComments(
			String className, long classPK, int status, int start, int end); @Override int getRootCommentsCount(
		String className, long classPK, int status); @Override boolean hasDiscussion(String className, long classPK); @Override void moveDiscussionToTrash(String className, long classPK); @Override void restoreDiscussionFromTrash(String className, long classPK); @Override void subscribeDiscussion(
			long userId, long groupId, String className, long classPK); @Override void unsubscribeDiscussion(
			long userId, String className, long classPK); @Override long updateComment(
			long userId, String className, long classPK, long commentId,
			String subject, String body,
			Function<String, ServiceContext> serviceContextFunction);  }
@Test public void testAddComment() throws Exception { _mbCommentManagerImpl.addComment( _USER_ID, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, _BODY, _serviceContextFunction); Mockito.verify( _mbMessageLocalService ).addDiscussionMessage( _USER_ID, StringPool.BLANK, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, _THREAD_ID, _ROOT_MESSAGE_ID, StringPool.BLANK, _BODY, _serviceContext ); Mockito.verify( _mbMessageLocalService ).getThreadMessages( _THREAD_ID, WorkflowConstants.STATUS_APPROVED ); }
@Test public void testAddCommentWithUserNameAndSubject() throws Exception { when( _mbMessage.getMessageId() ).thenReturn( _MBMESSAGE_ID ); Assert.assertEquals( _MBMESSAGE_ID, _mbCommentManagerImpl.addComment( _USER_ID, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, _USER_NAME, _SUBJECT, _BODY, _serviceContextFunction)); Mockito.verify( _mbMessageLocalService ).addDiscussionMessage( _USER_ID, _USER_NAME, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, _THREAD_ID, _ROOT_MESSAGE_ID, _SUBJECT, _BODY, _serviceContext ); Mockito.verify( _mbMessageLocalService ).getDiscussionMessageDisplay( _USER_ID, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, WorkflowConstants.STATUS_APPROVED ); }
@Test(expected = DuplicateCommentException.class) public void testAddDuplicateComment() throws Exception { setUpExistingComment(_BODY); _mbCommentManagerImpl.addComment( _USER_ID, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, _BODY, _serviceContextFunction); }
@Test public void testAddUniqueComment() throws Exception { setUpExistingComment(_BODY + RandomTestUtil.randomString()); _mbCommentManagerImpl.addComment( _USER_ID, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, _BODY, _serviceContextFunction); Mockito.verify( _mbMessageLocalService ).addDiscussionMessage( _USER_ID, StringPool.BLANK, _GROUP_ID, _CLASS_NAME, _ENTRY_ID, _THREAD_ID, _ROOT_MESSAGE_ID, StringPool.BLANK, _BODY, _serviceContext ); }