### Question:
ForumServiceImpl implements ForumService { @Override public void addTopMessage(Forum forum, Message topMessage, Identity creator, PublishEventTO publishEventTO) { topMessage.setForum(forum); topMessage.setParent(null); topMessage.setThreadtop(null); topMessage.setCreator(creator); forumDao.saveMessage(topMessage); publishEventTO.setSourceEntryId(topMessage.getKey().toString()); publishEvent(publishEventTO); } ForumServiceImpl();   ForumServiceImpl(ForumDao forumManagerMock); @Override List<Message> getThread(Long msgid); @Override List<Long> getAllForumKeys(); @Override List<Message> getMessagesByForum(final Forum forum); @Override List<Message> getMessagesByForumID(Long forum_id); @Override Integer countMessagesByForumID(Long forumkey); @Override int countReadMessagesByUserAndForum(Identity identity, Long forumkey); @Override List<Message> getNewMessageInfo(Long forumKey, Date latestRead); @Override Forum addAForum(); @Override Forum loadForum(Long forumKey); @Override void deleteForum(Long forumKey); @Override void replyToMessage(Identity creator, Message replyToMessage, Message newMessage, PublishEventTO publishEventTO); @Override void addTopMessage(Forum forum, Message topMessage, Identity creator, PublishEventTO publishEventTO); @Override Message loadMessage(Long messageKey); @Override Message createMessage(); void saveMessage(final Message m); @Override void updateMessage(Identity updater, Message updatedMessage, boolean updateLastModifiedDate, ForumChangedEvent event, PublishEventTO publishEventTO); void updateCounters(final Message m); @Override void deleteMessageTree(Long forumKey, Message m); @Override boolean hasChildren(Message m); @Override OlatRootFolderImpl getMessageContainer(Long forumKey, Long messageKey); @Override Message findMessage(Long messageId); @Override Message splitThread(Identity updater, final Message msg); @Override Message moveMessage(Identity updater, final Message msg, final Message topMsg); @Override Set<Long> getReadSet(Identity identity, Forum forum); @Override void markAsRead(Identity identity, Message msg); OlatRootFolderImpl getForumContainer(final Long forumKey); String getFileSize(final Long forumKey); @Override VFSContainer getForumArchiveContainer(final Identity identity, final Long forumKey); @Override VFSContainer getTempUploadFolder();  }### Answer:
@Test public void addTopMessage() { Forum mockForum = mock(Forum.class); when(mockForum.getResourceableId()).thenReturn(new Long(1234)); Identity initiatorIdentity = mock(Identity.class); Message firstMessage = new MessageMockImpl(); publishEventTO = createPublishEventTO(initiatorIdentity); forumService.addTopMessage(mockForum, firstMessage, initiatorIdentity, publishEventTO); assertEquals(mockForum, firstMessage.getForum()); assertEquals(initiatorIdentity, firstMessage.getCreator()); assertEquals(null, firstMessage.getParent()); assertEquals(null, firstMessage.getThreadtop()); }
@Test(expected = RuntimeException.class) public void addTopMessageWithNullMessage() { Forum realForum = new ForumImpl(); Identity initiatorIdentity = mock(Identity.class); Message firstMessage = null; publishEventTO = createPublishEventTO(initiatorIdentity); forumService.addTopMessage(realForum, firstMessage, initiatorIdentity, publishEventTO); }