ForumServiceImpl implements ForumService { @Override public Message splitThread(Identity updater, final Message msg) { Message newTopMessage = null; if (msg.getThreadtop() == null) { newTopMessage = msg; } else { final List<Message> threadList = this.getThread(msg.getThreadtop().getKey()); final List<Message> subthreadList = new ArrayList<Message>(); subthreadList.add(msg); getSubthread(msg, threadList, subthreadList); final Iterator<Message> messageIterator = subthreadList.iterator(); Message firstMessage = null; if (messageIterator.hasNext()) { firstMessage = messageIterator.next(); firstMessage = forumDao.loadMessage(firstMessage); firstMessage.setParent(null); firstMessage.setThreadtop(null); this.updateMessage(updater, firstMessage, false, new ForumChangedEvent("split"), PublishEventTO.getNoPublishInstance()); newTopMessage = firstMessage; } while (firstMessage != null && messageIterator.hasNext()) { Message message = messageIterator.next(); message = forumDao.loadMessage(message); message.setThreadtop(firstMessage); this.updateMessage(updater, message, false, null, PublishEventTO.getNoPublishInstance()); } } return newTopMessage; } 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();  }
@Test public void splitThread() { Message topMessage = new MessageImpl(); Message message2 = new MessageImpl(); message2.setParent(topMessage); Message message3 = new MessageImpl(); message3.setParent(message2); Message message4 = new MessageImpl(); message4.setParent(message3); Message newTopMessage = forumService.splitThread(updaterIdentity, message3); assertEquals(message3, newTopMessage); }
@Test(expected = RuntimeException.class) public void splitThreadWithNull() { forumService.splitThread(updaterIdentity, null); }