Controller implements NetworkConnectionListener { public void removeUser(final User user, final String privateSystemMessage) { final UserList userList = getUserList(); user.setOnline(false); cancelFileTransfers(user); userList.remove(user); if (user.getPrivchat() != null) { msgController.showPrivateSystemMessage(user, privateSystemMessage); user.getPrivchat().setLoggedOff(); } closePrivateChatLogger(user); } Controller(final UserInterface ui, final Settings settings, final SettingsSaver settingsSaver,
                      final CoreMessages coreMessages, final ErrorHandler errorHandler); void start(); Topic getTopic(); UserList getUserList(); boolean isWrote(); void changeWriting(final int code, final boolean writing); void updateMeWriting(final boolean isCurrentlyWriting); void goAway(final String awayMessage); void comeBack(); void changeAwayStatus(final int code, final boolean away, final String awaymsg); boolean isNickInUse(final String nick); boolean isNewUser(final int code); void changeMyNick(final String newNick); void changeNick(final int code, final String nick); void saveSettings(); @Nullable User getUser(final int code); @Nullable User getUser(final String nick); void logOn(); void logOff(final boolean removeUsers); void removeUser(final User user, final String privateSystemMessage); void cancelFileTransfers(final User user); void shutdown(); void sendExposeMessage(); void sendExposingMessage(); void sendGetTopicMessage(); void sendIdleMessage(); void sendChatMessage(final String msg); void sendTopicRequestedMessage(); void changeTopic(final String newTopic); void sendNickCrashMessage(final String nick); void sendFileAbort(final User user, final int fileHash, final String fileName); void sendFileAccept(final User user, final int port, final int fileHash, final String fileName); void sendFile(final User user, final FileToSend file); TransferList getTransferList(); WaitingList getWaitingList(); void updateAfterTimeout(); void sendClientInfo(); void sendPrivateMessage(final String privmsg, final User user); void changeNewMessage(final int code, final boolean newMsg); boolean isConnected(); void checkNetwork(); boolean isLoggedOn(); AutoCompleter getAutoCompleter(); @Override void beforeNetworkCameUp(); @Override void networkCameUp(final boolean silent); @Override void networkWentDown(final boolean silent); ChatState getChatState(); JMXBeanLoader createJMXBeanLoader(); void registerNetworkConnectionListener(final NetworkConnectionListener listener);  }
@Test public void removeUserShouldCancelFileTransfers() { final User user = new User("User1", 124); userList.add(user); final FileReceiver fileReceiver1 = mock(FileReceiver.class); final FileReceiver fileReceiver2 = mock(FileReceiver.class); when(transferList.getFileReceivers(user)).thenReturn(Arrays.asList(fileReceiver1, fileReceiver2)); final FileSender fileSender1 = mock(FileSender.class); final FileSender fileSender2 = mock(FileSender.class); when(transferList.getFileSenders(user)).thenReturn(Arrays.asList(fileSender1, fileSender2)); controller.removeUser(user, "Bla bla"); verify(fileReceiver1).cancel(); verify(fileReceiver2).cancel(); verify(fileSender1).cancel(); verify(fileSender2).cancel(); verify(transferList).removeFileReceiver(fileReceiver1); verify(transferList).removeFileReceiver(fileReceiver2); verify(transferList).removeFileSender(fileSender1); verify(transferList).removeFileSender(fileSender2); }
@Test public void removeUserShouldLogOffPrivateChat() { final User user = new User("User1", 124); userList.add(user); final PrivateChatWindow privchat = mock(PrivateChatWindow.class); user.setPrivchat(privchat); controller.removeUser(user, "Bla bla"); verify(messageController).showPrivateSystemMessage(user, "Bla bla"); verify(privchat).setLoggedOff(); }
@Test public void removeUserShouldClosePrivateChatLogger() { final User user = new User("User1", 124); userList.add(user); final ChatLogger chatLogger = mock(ChatLogger.class); user.setPrivateChatLogger(chatLogger); controller.removeUser(user, "Bla bla"); verify(chatLogger).close(); }
@Test public void removeUserShouldRemoveUserAndSetOffline() { final User user = new User("User1", 124); userList.add(user); assertEquals(1, userList.indexOf(user)); assertTrue(user.isOnline()); controller.removeUser(user, "Bla bla"); assertEquals(-1, userList.indexOf(user)); assertFalse(user.isOnline()); }