CommandParser { public void fixTopic(final String newTopic) throws CommandException { final Topic topic = controller.getTopic(); final String trimTopic = newTopic.trim(); if (!trimTopic.equals(topic.getTopic().trim())) { controller.changeTopic(trimTopic); if (trimTopic.length() > 0) { msgController.showSystemMessage(coreMessages.getMessage("core.command.topic.systemMessage.topicChanged", trimTopic)); } else { msgController.showSystemMessage(coreMessages.getMessage("core.command.topic.systemMessage.topicRemoved")); } ui.showTopic(); } } CommandParser(final Controller controller, final UserInterface ui, final Settings settings,
                         final CoreMessages coreMessages); void fixTopic(final String newTopic); void sendFile(final User user, final FileToSend file); void cancelFileTransfer(final FileTransfer fileTransfer); void showCommands(); void parse(final String line);  }
@Test public void fixTopicShouldDoNothingIfTopicIsUnchanged() throws CommandException { topic.changeTopic(new Topic("Hey there", "Peter", 12345678)); parser.fixTopic("Hey there"); verify(controller).getTopic(); verifyNoMoreInteractions(controller); verifyZeroInteractions(messageController, userInterface); }
@Test public void fixTopicShouldDoNothingIfTopicIsUnchangedIncludingTrim() throws CommandException { topic.changeTopic(new Topic("Hey there ", "Peter", 12345678)); parser.fixTopic(" Hey there"); verify(controller).getTopic(); verifyNoMoreInteractions(controller); verifyZeroInteractions(messageController, userInterface); }
@Test public void fixTopicShouldChangeAndUpdateAndNotifyRemovedTopic() throws CommandException { topic.changeTopic(new Topic("Topic", "Peter", 12345678)); parser.fixTopic(" "); verify(controller).changeTopic(""); verify(messageController).showSystemMessage("You removed the topic"); verify(userInterface).showTopic(); }
@Test public void fixTopicShouldChangeAndUpdateAndNotifyNewTopic() throws CommandException { topic.changeTopic(new Topic("Topic", "Peter", 12345678)); parser.fixTopic(" new topic"); verify(controller).changeTopic("new topic"); verify(messageController).showSystemMessage("You changed the topic to: new topic"); verify(userInterface).showTopic(); }
@Test public void fixTopicShouldChangeAndUpdateAndNotifyNewTopicIfTopicIsNotSet() throws CommandException { assertFalse(topic.hasTopic()); parser.fixTopic(" new topic"); verify(controller).changeTopic("new topic"); verify(messageController).showSystemMessage("You changed the topic to: new topic"); verify(userInterface).showTopic(); }