DefaultMessageResponder implements MessageResponder { @Override public void topicChanged(final int userCode, final String newTopic, final String nick, final long time) { if (time > 0 && nick.length() > 0) { final Topic topic = controller.getTopic(); if (newTopic != null) { if (!newTopic.equals(topic.getTopic()) && time > topic.getTime()) { if (chatState.isLogonCompleted()) { msgController.showSystemMessage(nick + " changed the topic to: " + newTopic); } else { final String date = dateTools.dateToString(new Date(time), "HH:mm:ss, dd. MMM. yy"); msgController.showSystemMessage("Topic is: " + newTopic + " (set by " + nick + " at " + date + ")"); } topic.changeTopic(newTopic, nick, time); ui.showTopic(); } } else { if (!topic.getTopic().equals(newTopic) && time > topic.getTime() && chatState.isLogonCompleted()) { msgController.showSystemMessage(nick + " removed the topic"); topic.changeTopic("", "", time); ui.showTopic(); } } } } DefaultMessageResponder(final Controller controller, final UserInterface ui, final Settings settings,
                                   final CoreMessages coreMessages); @Override void messageArrived(final int userCode, final String msg, final int color); @Override void userLogOff(final int userCode); @Override void userLogOn(final User newUser); @Override void topicChanged(final int userCode, final String newTopic, final String nick, final long time); @Override void userExposing(final User user); @Override void meLogOn(final String ipAddress); @Override void writingChanged(final int userCode, final boolean writing); @Override void awayChanged(final int userCode, final boolean away, final String awayMsg); @Override void meIdle(final String ipAddress); @Override void userIdle(final int userCode, final String ipAddress); @Override void topicRequested(); @Override void nickCrash(); @Override void exposeRequested(); @Override void nickChanged(final int userCode, final String newNick); @Override void fileSend(final int userCode, final long byteSize, final String fileName, final String user, final int fileHash); @Override void fileSendAborted(final int userCode, final String fileName, final int fileHash); @Override void fileSendAccepted(final int userCode, final String fileName, final int fileHash, final int port); @Override void clientInfo(final int userCode, final String client, final long timeSinceLogon,
                           final String operatingSystem, final int privateChatPort, final int tcpChatPort);  }
@Test public void topicChangedShouldDoNothingWhenTimeIsZero() { responder.topicChanged(300, "Nothing", "Harry", 0); verifyZeroInteractions(messageController, userInterface); }
@Test public void topicChangedShouldDoNothingWhenNickNameIsEmpty() { responder.topicChanged(300, "Nothing", "", 1000); verifyZeroInteractions(messageController, userInterface); }
@Test public void topicChangedShouldUpdateTopicAndShowTopicIsMessageWhenNotDoneWithLogonYet() { final Topic topic = new Topic(); when(controller.getTopic()).thenReturn(topic); when(chatState.isLogonCompleted()).thenReturn(false); final long time = new DateTime().withDate(2013, 8, 22).withTime(13, 45, 5, 0).toDate().getTime(); responder.topicChanged(300, "See ya!", "Harry", time); verify(messageController).showSystemMessage("Topic is: See ya! (set by Harry at 13:45:05, 22. Aug. 13)"); verify(userInterface).showTopic(); verifyTopic(topic, "See ya!", "Harry", time); }
@Test public void topicChangedShouldUpdateTopicAndShowTopicChangedMessageWhenDoneWithLogon() { final Topic topic = new Topic(); when(controller.getTopic()).thenReturn(topic); when(chatState.isLogonCompleted()).thenReturn(true); final long time = System.currentTimeMillis(); responder.topicChanged(300, "See ya!", "Harry", time); verify(messageController).showSystemMessage("Harry changed the topic to: See ya!"); verify(userInterface).showTopic(); verifyTopic(topic, "See ya!", "Harry", time); }
@Test public void topicChangedShouldDoNothingIfNewTopicIsTheSameAsTheOldTopic() { final Topic topic = new Topic("Old topic", "Niles", 1000); when(controller.getTopic()).thenReturn(topic); responder.topicChanged(300, "Old topic", "Niles", 2000); verifyZeroInteractions(messageController, userInterface); verifyTopic(topic, "Old topic", "Niles", 1000); }
@Test public void topicChangedShouldDoNothingIfNewTopicHasOlderTimestamp() { final Topic topic = new Topic("Old topic", "Niles", 2000); when(controller.getTopic()).thenReturn(topic); responder.topicChanged(300, "Older topic", "Niles", 1000); verifyZeroInteractions(messageController, userInterface); verifyTopic(topic, "Old topic", "Niles", 2000); }
@Test public void topicChangedShouldUpdateTopicAndShowTopicRemovedMessageWhenTopicIsNull() { final Topic topic = new Topic(); when(controller.getTopic()).thenReturn(topic); when(chatState.isLogonCompleted()).thenReturn(true); final long time = System.currentTimeMillis(); responder.topicChanged(300, null, "Harry", time); verify(messageController).showSystemMessage("Harry removed the topic"); verify(userInterface).showTopic(); verifyTopic(topic, "", "", time); }
@Test public void topicChangedShouldDoNothingWhenTopicIsNullButNotDoneWithLogonYet() { final Topic topic = new Topic(); when(controller.getTopic()).thenReturn(topic); when(chatState.isLogonCompleted()).thenReturn(false); responder.topicChanged(300, null, "Harry", System.currentTimeMillis()); verifyZeroInteractions(messageController, userInterface); verifyTopic(topic, "", "", 0); }
@Test public void topicChangedShouldDoNothingWhenTopicIsNullButTimeIsOlderThanCurrentTopic() { final Topic topic = new Topic("Current topic", "Harry", 2000); when(controller.getTopic()).thenReturn(topic); when(chatState.isLogonCompleted()).thenReturn(true); responder.topicChanged(300, null, "Harry", 1000); verifyZeroInteractions(messageController, userInterface); verifyTopic(topic, "Current topic", "Harry", 2000); }