DefaultMessageResponder implements MessageResponder { @Override public void messageArrived(final int userCode, final String msg, final int color) { if (!controller.isNewUser(userCode)) { final User user = controller.getUser(userCode); if (!user.isAway()) { msgController.showUserMessage(user.getNick(), msg, color); if (ui.isVisible() && !ui.isFocused()) { me.setNewMsg(true); } ui.notifyMessageArrived(user, msg); } else { LOG.severe("User is away - ignoring message. user=%s, userCode=%s, message=%s", user, userCode, msg); } } else { LOG.severe("User is unknown - ignoring message. userCode=%s, message=%s", userCode, msg); } } 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 messageArrivedShouldShowMessageAndNotifyUserInterfaceAndSetNewMessageFlagWhenVisibleButNotFocused() { setUpExistingUser(); when(userInterface.isVisible()).thenReturn(true); when(userInterface.isFocused()).thenReturn(false); responder.messageArrived(100, "msg", 200); verify(messageController).showUserMessage("Tester", "msg", 200); verify(userInterface).notifyMessageArrived(user, "msg"); assertTrue(me.isNewMsg()); }
@Test public void messageArrivedShouldShowMessageAndNotifyUserInterfaceButNotSetNewMessageFlagWhenVisibleAndFocused() { setUpExistingUser(); when(userInterface.isVisible()).thenReturn(true); when(userInterface.isFocused()).thenReturn(true); responder.messageArrived(100, "msg2", 200); verify(messageController).showUserMessage("Tester", "msg2", 200); verify(userInterface).notifyMessageArrived(user, "msg2"); assertFalse(me.isNewMsg()); }
@Test public void messageArrivedShouldShowMessageAndNotifyUserInterfaceButNotSetNewMessageFlagWhenNotVisible() { setUpExistingUser(); when(userInterface.isVisible()).thenReturn(false); when(userInterface.isFocused()).thenReturn(false); responder.messageArrived(100, "msg3", 200); verify(messageController).showUserMessage("Tester", "msg3", 200); verify(userInterface).notifyMessageArrived(user, "msg3"); assertFalse(me.isNewMsg()); }
@Test public void messageArrivedShouldDoNothingIfUserIsAway() { setUpExistingUser(); user.setAway(true); responder.messageArrived(100, "msg", 200); verifyZeroInteractions(messageController, userInterface); }
@Test public void messageArrivedShouldDoNothingIfUserIsUnknown() { setUpUnknownUser(); responder.messageArrived(100, "msg", 200); verifyZeroInteractions(messageController, userInterface); }