DefaultMessageResponder implements MessageResponder { @Override public void userLogOn(final User newUser) { if (me.getNick().trim().equalsIgnoreCase(newUser.getNick())) { LOG.severe("User logs on with your nick name - resetting nick and sending nick crash message. " + "user=%s, userCode=%s", newUser, newUser.getCode()); controller.sendNickCrashMessage(newUser.getNick()); newUser.setNick("" + newUser.getCode()); } else if (controller.isNickInUse(newUser.getNick())) { LOG.severe("User logs on with someone else's nick name - resetting nick. " + "user=%s, userCode=%s", newUser, newUser.getCode()); newUser.setNick("" + newUser.getCode()); } else if (!Tools.isValidNick(newUser.getNick())) { LOG.severe("User logs on with invalid nick name - resetting nick. " + "user=%s, userCode=%s", newUser, newUser.getCode()); newUser.setNick("" + newUser.getCode()); } wList.removeWaitingUser(newUser.getCode()); controller.getUserList().add(newUser); msgController.showSystemMessage(newUser.getNick() + " logged on from " + newUser.getIpAddress()); } 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 userLogOnShouldAddUserToListAndShowSystemMessage() { responder.userLogOn(user); assertEquals(0, userList.indexOf(user)); verify(messageController).showSystemMessage("Tester logged on from 192.168.10.123"); verify(waitingList).removeWaitingUser(user.getCode()); }
@Test public void userLogOnShouldResetNickAndSendNickCrashMessageFirstIfUserHasMyNick() { user.setNick("me"); responder.userLogOn(user); assertEquals(0, userList.indexOf(user)); verify(messageController).showSystemMessage("100 logged on from 192.168.10.123"); verify(controller).sendNickCrashMessage("me"); }
@Test public void userLogOnShouldResetNickFirstIfUserHasNickNameInUseBySomeoneElse() { when(controller.isNickInUse("Tester")).thenReturn(true); responder.userLogOn(user); assertEquals(0, userList.indexOf(user)); verify(messageController).showSystemMessage("100 logged on from 192.168.10.123"); verify(controller, never()).sendNickCrashMessage(anyString()); }
@Test public void userLogOnShouldResetNickFirstIfUserHasInvalidNickName() { user.setNick("No!"); responder.userLogOn(user); assertEquals(0, userList.indexOf(user)); verify(messageController).showSystemMessage("100 logged on from 192.168.10.123"); verify(controller, never()).sendNickCrashMessage(anyString()); }