ForumServiceImpl implements ForumService { protected Message cloneMessageAndAssignNewParent(Identity updater, final Message msg, final Message topMsg) { final List<Message> oldThreadList = getThread(msg.getThreadtop().getKey()); final List<Message> subThreadList = new ArrayList<Message>(); this.getSubthread(msg, oldThreadList, subThreadList); for (Message childMessage : subThreadList) { childMessage = forumDao.loadMessage(childMessage); childMessage.setParent(msg.getParent()); updateMessage(updater, childMessage, false, null, PublishEventTO.getNoPublishInstance()); } final Message oldMessage = forumDao.loadMessage(msg); final Message message = createMessage(); message.setCreator(oldMessage.getCreator()); message.setForum(oldMessage.getForum()); message.setModifier(oldMessage.getModifier()); message.setTitle(oldMessage.getTitle()); message.setBody(oldMessage.getBody()); message.setThreadtop(topMsg); message.setParent(topMsg); final Status status = Status.getStatus(oldMessage.getStatusCode()); status.setMoved(true); message.setStatusCode(Status.getStatusCode(status)); forumDao.saveMessage(message); return message; } 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 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); @Override VFSContainer getForumContainer(final Long forumKey); @Override String getForumContainerSize(final Long forumKey); @Override VFSContainer getMessageContainer(Long forumKey, Long messageKey); @Override VFSContainer getForumArchiveContainer(final Identity identity, final Long forumKey); @Override VFSContainer getTempUploadFolder();  }
@Test public void cloneMessageAndAssignNewParent() { Message movedMessage = forumService.cloneMessageAndAssignNewParent(updaterIdentity, movableMessage, moveTargetMessage); assertTrue("Asserts that the movedMessage has a new parent!", movedMessage.getParent() == moveTargetMessage); }
@Test(expected = RuntimeException.class) public void cloneMessageAndAssignNewParentWithNullMessage() { forumService.cloneMessageAndAssignNewParent(updaterIdentity, null, mock(Message.class)); }
@Test public void cloneMessageAndAssignNewParentWithNullTargetMessage() { Message movedMessage = forumService.cloneMessageAndAssignNewParent(updaterIdentity, movableMessage, null); assertTrue(movedMessage.getParent() == null); }