Controller implements NetworkConnectionListener { public void logOff(final boolean removeUsers) { networkMessages.sendLogoffMessage(); chatState.setLoggedOn(false); chatState.setLogonCompleted(false); networkService.disconnect(); getTopic().resetTopic(); if (removeUsers) { removeAllUsers(); } else { closeAllUserResources(); } me.reset(); } 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 logOffShouldClosePrivateChatLoggersWhenRemoveUsersIsTrue() { final User user1 = new User("User1", 124); final ChatLogger chatLogger1 = mock(ChatLogger.class); user1.setPrivateChatLogger(chatLogger1); final User user2 = new User("User2", 125); final ChatLogger chatLogger2 = mock(ChatLogger.class); user2.setPrivateChatLogger(chatLogger2); userList.add(user1); userList.add(user2); controller.logOff(true); verify(chatLogger1).close(); verify(chatLogger2).close(); }
@Test public void logOffShouldClosePrivateChatLoggersWhenRemoveUsersIsFalse() { final User user1 = new User("User1", 124); final ChatLogger chatLogger1 = mock(ChatLogger.class); user1.setPrivateChatLogger(chatLogger1); final User user2 = new User("User2", 125); final ChatLogger chatLogger2 = mock(ChatLogger.class); user2.setPrivateChatLogger(chatLogger2); userList.add(user1); userList.add(user2); controller.logOff(false); verify(chatLogger1).close(); verify(chatLogger2).close(); }
@Test public void logOffShouldCancelFileTransfersWhenRemoveUsersIsTrue() { final User user1 = new User("User1", 124); userList.add(user1); final FileReceiver fileReceiver1 = mock(FileReceiver.class); when(transferList.getFileReceivers(user1)).thenReturn(Arrays.asList(fileReceiver1)); final User user2 = new User("User2", 125); userList.add(user2); final FileSender fileSender1 = mock(FileSender.class); when(transferList.getFileSenders(user2)).thenReturn(Arrays.asList(fileSender1)); controller.logOff(true); verify(fileReceiver1).cancel(); verify(fileSender1).cancel(); verify(transferList).removeFileReceiver(fileReceiver1); verify(transferList).removeFileSender(fileSender1); }
@Test public void logOffShouldCancelFileTransfersWhenRemoveUsersIsFalse() { final User user1 = new User("User1", 124); userList.add(user1); final FileReceiver fileReceiver1 = mock(FileReceiver.class); when(transferList.getFileReceivers(user1)).thenReturn(Arrays.asList(fileReceiver1)); final User user2 = new User("User2", 125); userList.add(user2); final FileSender fileSender1 = mock(FileSender.class); when(transferList.getFileSenders(user2)).thenReturn(Arrays.asList(fileSender1)); controller.logOff(false); verify(fileReceiver1).cancel(); verify(fileSender1).cancel(); verify(transferList).removeFileReceiver(fileReceiver1); verify(transferList).removeFileSender(fileSender1); }