Controller implements NetworkConnectionListener { public void sendFile(final User user, final FileToSend file) throws CommandException { Validate.notNull(user, "User can not be null"); Validate.notNull(file, "File can not be null"); if (user.isMe()) { throw new CommandException(coreMessages.getMessage("core.sendFile.error.isMe")); } else if (!isConnected()) { throw new CommandException(coreMessages.getMessage("core.sendFile.error.notConnected")); } else if (me.isAway()) { throw new CommandException(coreMessages.getMessage("core.sendFile.error.meIsAway")); } else if (user.isAway()) { throw new CommandException(coreMessages.getMessage("core.sendFile.error.userIsAway")); } else if (Tools.getBytes(file.getName()) > Constants.MESSAGE_MAX_BYTES) { throw new CommandException(coreMessages.getMessage("core.sendFile.error.messageTooLong", Constants.MESSAGE_MAX_BYTES)); } else { networkMessages.sendFile(user, file); } } 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 sendFileShouldThrowExceptionIfUserIsNull() throws CommandException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("User can not be null"); controller.sendFile(null, mock(FileToSend.class)); }
@Test public void sendFileShouldThrowExceptionIfFileIsNull() throws CommandException { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("File can not be null"); controller.sendFile(mock(User.class), null); }
@Test public void sendFileShouldThrowExceptionIfUserIsMe() throws CommandException { expectedException.expect(CommandException.class); expectedException.expectMessage("You can not send a file to yourself"); final User user = mock(User.class); when(user.isMe()).thenReturn(true); controller.sendFile(user, mock(FileToSend.class)); }
@Test public void sendFileShouldThrowExceptionIfNotConnected() throws CommandException { expectedException.expect(CommandException.class); expectedException.expectMessage("You can not send a file without being connected"); controller.sendFile(mock(User.class), mock(FileToSend.class)); }