CommandParser { public void parse(final String line) { @NonNls final String command; if (line.contains(" ")) { command = line.substring(1, line.indexOf(' ')); } else { command = line.substring(1, line.length()); } if (command.length() > 0) { final String args = line.replaceFirst("/" + Pattern.quote(command), ""); if (command.equals("topic")) { cmdTopic(args); } else if (command.equals("away")) { cmdAway(args); } else if (command.equals("back")) { cmdBack(); } else if (command.equals("clear")) { cmdClear(); } else if (command.equals("about")) { cmdAbout(); } else if (command.equals("help")) { cmdHelp(); } else if (command.equals("whois")) { cmdWhois(args); } else if (command.equals("send")) { cmdSend(args); } else if (command.equals("receive")) { cmdReceive(args); } else if (command.equals("reject")) { cmdReject(args); } else if (command.equals("cancel")) { cmdCancel(args); } else if (command.equals("msg")) { cmdMsg(args); } else if (command.equals("nick")) { cmdNick(args); } else if (command.equals("users")) { cmdUsers(); } else if (command.equals("transfers")) { cmdTransfers(); } else if (command.equals("quit")) { cmdQuit(); } else if (command.startsWith("/")) { cmdSlash(line); } else { cmdUnknown(command); } } else { cmdUnknown(command); } } CommandParser(final Controller controller, final UserInterface ui, final Settings settings,
                         final CoreMessages coreMessages); void fixTopic(final String newTopic); void sendFile(final User user, final FileToSend file); void cancelFileTransfer(final FileTransfer fileTransfer); void showCommands(); void parse(final String line);  }
@Test public void transfersShouldShowSystemMessageWithActiveReceiver() { final FileReceiver fileReceiver = createFileReceiver(5, "image.png", 500L, 12, 80L, "Amy"); when(transferList.getFileReceivers()).thenReturn(Arrays.asList(fileReceiver)); parser.parse("/transfers"); verify(messageController).showSystemMessage("File transfers:\n" + "- Receiving:\n" + " #5 image.png [500.00KB] (12%, 80.00KB/s) from Amy"); }
@Test public void transfersShouldShowSystemMessageWithMultipleActiveReceivers() { final FileReceiver fileReceiver1 = createFileReceiver(1, "video.mp4", 15000L, 44, 56L, "Amy"); final FileReceiver fileReceiver2 = createFileReceiver(2, "kou.png", 10L, 80, 5L, "Donald"); final FileReceiver fileReceiver3 = createFileReceiver(4, "radiohead.mp3", 3500L, 25, 103L, "Dolly"); when(transferList.getFileReceivers()).thenReturn(Arrays.asList(fileReceiver1, fileReceiver2, fileReceiver3)); parser.parse("/transfers"); verify(messageController).showSystemMessage("File transfers:\n" + "- Receiving:\n" + " #1 video.mp4 [14.65MB] (44%, 56.00KB/s) from Amy\n" + " #2 kou.png [10.00KB] (80%, 5.00KB/s) from Donald\n" + " #4 radiohead.mp3 [3.42MB] (25%, 103.00KB/s) from Dolly"); }
@Test public void transfersShouldShowSystemMessageWithBothActiveSenderAndReceiver() { final FileSender fileSender = createFileSender(1, "image1.png", 501L, 11, 81L, "Amber"); when(transferList.getFileSenders()).thenReturn(Arrays.asList(fileSender)); final FileReceiver fileReceiver = createFileReceiver(2, "image2.png", 502L, 12, 82L, "Donna"); when(transferList.getFileReceivers()).thenReturn(Arrays.asList(fileReceiver)); parser.parse("/transfers"); verify(messageController).showSystemMessage("File transfers:\n" + "- Sending:\n" + " #1 image1.png [501.00KB] (11%, 81.00KB/s) to Amber\n" + "- Receiving:\n" + " #2 image2.png [502.00KB] (12%, 82.00KB/s) from Donna"); }
@Test public void transfersShouldShowSystemMessageWithMultipleActiveSendersAndReceivers() { final FileSender fileSender1 = createFileSender(1, "image1.png", 501L, 11, 81L, "Amber"); final FileSender fileSender2 = createFileSender(3, "image3.png", 503L, 13, 83L, "Lilly"); when(transferList.getFileSenders()).thenReturn(Arrays.asList(fileSender1, fileSender2)); final FileReceiver fileReceiver1 = createFileReceiver(2, "image2.png", 502L, 12, 82L, "Donna"); final FileReceiver fileReceiver2 = createFileReceiver(4, "image4.png", 504L, 14, 84L, "Kelly"); when(transferList.getFileReceivers()).thenReturn(Arrays.asList(fileReceiver1, fileReceiver2)); parser.parse("/transfers"); verify(messageController).showSystemMessage("File transfers:\n" + "- Sending:\n" + " #1 image1.png [501.00KB] (11%, 81.00KB/s) to Amber\n" + " #3 image3.png [503.00KB] (13%, 83.00KB/s) to Lilly\n" + "- Receiving:\n" + " #2 image2.png [502.00KB] (12%, 82.00KB/s) from Donna\n" + " #4 image4.png [504.00KB] (14%, 84.00KB/s) from Kelly"); }
@Test public void quitShouldQuit() { parser.parse("/quit"); verify(userInterface).quit(); }
@Test public void ekstraSlashShouldBeTreatedAsRegularMessage() throws CommandException { parser.parse(" verify(controller).sendChatMessage("/msg niles hello"); verify(messageController).showOwnMessage("/msg niles hello"); }
@Test public void ekstraSlashShouldShowSystemMessageIfChatMessageFails() throws CommandException { doThrow(new CommandException("No slash for you")).when(controller).sendChatMessage(anyString()); parser.parse(" verify(controller).sendChatMessage("/msg niles hello"); verify(messageController).showSystemMessage("No slash for you"); }
@Test public void unknownCommandShouldShowSystemMessage() { parser.parse("/nope"); verify(messageController).showSystemMessage("Unknown command 'nope'. Type /help for a list of commands"); }
@Test public void missingCommandShouldShowSystemMessage() { parser.parse("/"); verify(messageController).showSystemMessage("Unknown command ''. Type /help for a list of commands"); }
@Test public void rejectShouldReturnIfNoArguments() { parser.parse("/reject"); verify(messageController).showSystemMessage("/reject - missing arguments <nick> <id>"); }
@Test public void rejectShouldReturnIfOneArgument() { parser.parse("/reject SomeOne"); verify(messageController).showSystemMessage("/reject - missing arguments <nick> <id>"); }
@Test public void rejectShouldReturnIfThreeArguments() { parser.parse("/reject SomeOne some thing"); verify(messageController).showSystemMessage("/reject - missing arguments <nick> <id>"); }
@Test public void rejectShouldReturnIfUserDoesntExist() { parser.parse("/reject NoUser 1"); verify(messageController).showSystemMessage("/reject - no such user 'NoUser'"); }
@Test public void rejectShouldReturnIfUserIsMe() { when(controller.getUser("MySelf")).thenReturn(me); parser.parse("/reject MySelf 1"); verify(messageController).showSystemMessage("/reject - no point in doing that!"); }
@Test public void rejectShouldReturnIfFileTransferIdIsNotAnInteger() { setupSomeOne(); parser.parse("/reject SomeOne monkey"); verify(messageController).showSystemMessage("/reject - invalid file id argument: 'monkey'"); }
@Test public void rejectShouldReturnIfFileTransferIdDoesntExist() { final User someOne = setupSomeOne(); parser.parse("/reject SomeOne 1"); verify(transferList).getFileReceiver(someOne, 1); verify(messageController).showSystemMessage("/reject - no file with id 1 offered by SomeOne"); }
@Test public void rejectShouldReturnIfFileTransferHasAlreadyBeingAccepted() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); when(fileReceiver.isAccepted()).thenReturn(true); parser.parse("/reject SomeOne 1"); verify(transferList).getFileReceiver(someOne, 1); verify(messageController).showSystemMessage("/reject - already receiving 'doc.pdf' from SomeOne"); verify(fileReceiver, never()).reject(); }
@Test public void rejectShouldRejectFileTransferIfArgumentsMatch() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); parser.parse("/reject SomeOne 1"); verify(transferList).getFileReceiver(someOne, 1); verifyZeroInteractions(messageController); verify(fileReceiver).reject(); }
@Test public void rejectShouldRejectFileTransferIfArgumentsMatchEvenIfExtraSpaces() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); parser.parse("/reject SomeOne 1 "); verify(transferList).getFileReceiver(someOne, 1); verifyZeroInteractions(messageController); verify(fileReceiver).reject(); }
@Test public void receiveShouldReturnIfNoArguments() { parser.parse("/receive"); verify(messageController).showSystemMessage("/receive - missing arguments <nick> <id>"); }
@Test public void receiveShouldReturnIfOneArgument() { parser.parse("/receive SomeOne"); verify(messageController).showSystemMessage("/receive - missing arguments <nick> <id>"); }
@Test public void receiveShouldReturnIfThreeArguments() { parser.parse("/receive SomeOne some thing"); verify(messageController).showSystemMessage("/receive - missing arguments <nick> <id>"); }
@Test public void receiveShouldReturnIfUserDoesntExist() { parser.parse("/receive NoUser 1"); verify(messageController).showSystemMessage("/receive - no such user 'NoUser'"); }
@Test public void receiveShouldReturnIfUserIsMe() { when(controller.getUser("MySelf")).thenReturn(me); parser.parse("/receive MySelf 1"); verify(messageController).showSystemMessage("/receive - no point in doing that!"); }
@Test public void receiveShouldReturnIfFileTransferIdIsNotAnInteger() { setupSomeOne(); parser.parse("/receive SomeOne monkey"); verify(messageController).showSystemMessage("/receive - invalid file id argument: 'monkey'"); }
@Test public void receiveShouldReturnIfFileTransferIdDoesntExist() { final User someOne = setupSomeOne(); parser.parse("/receive SomeOne 1"); verify(transferList).getFileReceiver(someOne, 1); verify(messageController).showSystemMessage("/receive - no file with id 1 offered by SomeOne"); }
@Test public void receiveShouldReturnIfFileTransferHasAlreadyBeingAccepted() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); when(fileReceiver.isAccepted()).thenReturn(true); parser.parse("/receive SomeOne 1"); verify(transferList).getFileReceiver(someOne, 1); verify(messageController).showSystemMessage("/receive - already receiving 'doc.pdf' from SomeOne"); verify(fileReceiver, never()).accept(); }
@Test public void receiveShouldAcceptFileTransferIfArgumentsMatch() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); setupFile(fileReceiver); parser.parse("/receive SomeOne 1"); verify(transferList).getFileReceiver(someOne, 1); verifyZeroInteractions(messageController); verify(fileReceiver).accept(); }
@Test public void receiveShouldAcceptFileTransferIfArgumentsMatchEvenIfExtraSpaces() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); setupFile(fileReceiver); parser.parse("/receive SomeOne 1 "); verify(transferList).getFileReceiver(someOne, 1); verifyZeroInteractions(messageController); verify(fileReceiver).accept(); }
@Test public void receiveShouldAcceptFileTransferIfArgumentsMatchAndRenameExistingFile() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); final File file = setupFile(fileReceiver); when(file.exists()).thenReturn(true); final ArgumentCaptor<File> newFileCaptor = ArgumentCaptor.forClass(File.class); parser.parse("/receive SomeOne 1"); verify(transferList).getFileReceiver(someOne, 1); verify(messageController).showSystemMessage("/receive - file 'doc.pdf' already exists - renaming to 'doc_1.pdf'"); verify(fileReceiver).accept(); verify(fileReceiver).setFile(newFileCaptor.capture()); assertEquals("doc_1.pdf", newFileCaptor.getValue().getName()); }
@Test public void cancelShouldReturnIfNoArguments() { parser.parse("/cancel"); verify(messageController).showSystemMessage("/cancel - missing arguments <nick> <id>"); }
@Test public void cancelShouldReturnIfOneArgument() { parser.parse("/cancel SomeOne"); verify(messageController).showSystemMessage("/cancel - missing arguments <nick> <id>"); }
@Test public void cancelShouldReturnIfThreeArguments() { parser.parse("/cancel SomeOne some thing"); verify(messageController).showSystemMessage("/cancel - missing arguments <nick> <id>"); }
@Test public void cancelShouldReturnIfUserDoesntExist() { parser.parse("/cancel NoUser 1"); verify(messageController).showSystemMessage("/cancel - no such user 'NoUser'"); }
@Test public void cancelShouldReturnIfUserIsMe() { when(controller.getUser("MySelf")).thenReturn(me); parser.parse("/cancel MySelf 1"); verify(messageController).showSystemMessage("/cancel - no point in doing that!"); }
@Test public void cancelShouldReturnIfFileTransferIdIsNotAnInteger() { setupSomeOne(); parser.parse("/cancel SomeOne monkey"); verify(messageController).showSystemMessage("/cancel - invalid file id argument: 'monkey'"); }
@Test public void cancelShouldReturnIfFileTransferIdDoesntExist() { final User someOne = setupSomeOne(); parser.parse("/cancel SomeOne 1"); verify(transferList).getFileTransfer(someOne, 1); verify(messageController).showSystemMessage("/cancel - no file transfer with id 1 going on with SomeOne"); }
@Test public void cancelShouldReturnIfFileReceiverIsNotAccepted() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); parser.parse("/cancel SomeOne 1"); verify(transferList).getFileTransfer(someOne, 1); verify(messageController).showSystemMessage("/cancel - transfer of 'doc.pdf' from SomeOne has not started yet"); verify(fileReceiver, never()).cancel(); }
@Test public void cancelShouldCancelIfFileReceiverIsAccepted() { final User someOne = setupSomeOne(); final FileReceiver fileReceiver = setupFileReceiver(someOne); when(fileReceiver.isAccepted()).thenReturn(true); parser.parse("/cancel SomeOne 1"); verify(transferList).getFileTransfer(someOne, 1); verifyZeroInteractions(messageController); verify(fileReceiver).cancel(); }
@Test public void cancelShouldCancelIfFileSenderAndArgumentsMatch() { final User someOne = setupSomeOne(); final FileSender fileSender = setupFileSender(someOne); parser.parse("/cancel SomeOne 1"); verify(transferList).getFileTransfer(someOne, 1); verifyZeroInteractions(messageController); verify(fileSender).cancel(); }
@Test public void cancelShouldCancelAndNotifyRecipientIfFileSendIsWaiting() { final User someOne = setupSomeOne(); final FileSender fileSender = setupFileSender(someOne); when(fileSender.isWaiting()).thenReturn(true); final FileToSend file = setupFile(fileSender); when(fileSender.getUser()).thenReturn(someOne); parser.parse("/cancel SomeOne 1"); verify(transferList).getFileTransfer(someOne, 1); verify(transferList).removeFileSender(fileSender); verify(messageController).showSystemMessage("You cancelled sending of doc.pdf to SomeOne"); verify(controller).sendFileAbort(someOne, file.hashCode(), "doc.pdf"); verify(fileSender).cancel(); }
@Test public void awayShouldReturnIfNoArguments() { parser.parse("/away"); verify(messageController).showSystemMessage("/away - missing argument <away message>"); verifyZeroInteractions(controller); }
@Test public void awayShouldReturnIfAlreadyAway() { me.setAway(true); me.setAwayMsg("Gone with the wind"); parser.parse("/away again"); verify(messageController).showSystemMessage("/away - you are already away: 'Gone with the wind'"); verifyZeroInteractions(controller); }
@Test public void awayShouldSetAsAway() throws CommandException { parser.parse("/away Out shopping"); verify(controller).goAway("Out shopping"); verifyZeroInteractions(messageController); }
@Test public void awayShouldShowSystemMessageIfChangeFails() throws CommandException { doThrow(new CommandException("Don't go away")).when(controller).goAway(anyString()); parser.parse("/away Leaving for good"); verify(controller).goAway("Leaving for good"); verify(messageController).showSystemMessage("Don't go away"); }
@Test public void backShouldReturnIfNotAway() { parser.parse("/back"); verify(messageController).showSystemMessage("/back - you are not away"); verifyZeroInteractions(controller); }
@Test public void backShouldSetAsBack() throws CommandException { me.setAway(true); me.setAwayMsg("Just away"); parser.parse("/back"); verify(controller).comeBack(); verifyZeroInteractions(messageController); }
@Test public void backShouldShowSystemMessageIfChangeFails() throws CommandException { doThrow(new CommandException("Don't come back")).when(controller).comeBack(); me.setAway(true); me.setAwayMsg("Just away"); parser.parse("/back"); verify(controller).comeBack(); verify(messageController).showSystemMessage("Don't come back"); }
@Test public void clearShouldUseUserInterface() { parser.parse("/clear"); verify(userInterface).clearChat(); }
@Test public void aboutShouldShowVersionAndContactDetails() { parser.parse("/about"); verify(messageController).showSystemMessage( "This is KouChat v" + Constants.APP_VERSION + ", by Christian Ihle - contact@kouchat.net - https: }
@Test public void whoisShouldReturnIfNoArguments() { parser.parse("/whois"); verify(messageController).showSystemMessage("/whois - missing argument <nick>"); verifyNoMoreInteractions(messageController); }
@Test public void whoisShouldReturnIfUserNotFound() { parser.parse("/whois none"); verify(messageController).showSystemMessage("/whois - no such user 'none'"); verifyNoMoreInteractions(messageController); }
@Test public void whoisShouldShowUserDetailsForOnlineUser() { final User penny = new User("penny", 123); penny.setClient("TestClient"); penny.setOperatingSystem("Red Hat"); penny.setIpAddress("10.0.0.80"); penny.setLogonTime(56789); when(controller.getUser("penny")).thenReturn(penny); when(dateTools.howLongFromNow(anyLong())).thenReturn("Too long"); parser.parse("/whois penny"); verify(messageController).showSystemMessage("/whois - penny:\n" + "IP address: 10.0.0.80\n" + "Client: TestClient\n" + "Operating System: Red Hat\n" + "Online: Too long"); verifyNoMoreInteractions(messageController); verify(dateTools).howLongFromNow(56789); verify(controller).getUser("penny"); }
@Test public void whoisShouldShowUserDetailsForUserWithHostName() { final User amy = new User("Amy", 123); amy.setClient("JUnit"); amy.setOperatingSystem("DOS"); amy.setIpAddress("10.0.0.81"); amy.setHostName("amy.com"); when(controller.getUser("amy")).thenReturn(amy); when(dateTools.howLongFromNow(anyLong())).thenReturn("A year"); parser.parse("/whois amy"); verify(messageController).showSystemMessage("/whois - Amy:\n" + "IP address: 10.0.0.81\n" + "Host name: amy.com\n" + "Client: JUnit\n" + "Operating System: DOS\n" + "Online: A year"); }
@Test public void whoisShouldShowUserDetailsForUserWithTCP() { final User amy = new User("Amy", 123); amy.setClient("JUnit"); amy.setOperatingSystem("DOS"); amy.setIpAddress("10.0.0.81"); amy.setHostName("amy.com"); amy.setTcpEnabled(true); when(controller.getUser("amy")).thenReturn(amy); when(dateTools.howLongFromNow(anyLong())).thenReturn("A year"); parser.parse("/whois amy"); verify(messageController).showSystemMessage("/whois - Amy:\n" + "IP address: 10.0.0.81\n" + "Host name: amy.com\n" + "Client: JUnit TCP\n" + "Operating System: DOS\n" + "Online: A year"); }
@Test public void whoisShouldShowUserDetailsForUserWhoIsAway() { final User amy = new User("Amy", 123); amy.setClient("JUnit"); amy.setOperatingSystem("DOS"); amy.setIpAddress("10.0.0.81"); amy.setAway(true); amy.setAwayMsg("Gone home"); when(controller.getUser("amy")).thenReturn(amy); when(dateTools.howLongFromNow(anyLong())).thenReturn("A year"); parser.parse("/whois amy"); verify(messageController).showSystemMessage("/whois - Amy (Away):\n" + "IP address: 10.0.0.81\n" + "Client: JUnit\n" + "Operating System: DOS\n" + "Online: A year\n" + "Away message: Gone home"); }
@Test public void msgShouldReturnIfNoArguments() throws CommandException { parser.parse("/msg"); verify(messageController).showSystemMessage("/msg - missing arguments <nick> <msg>"); verify(controller, never()).sendPrivateMessage(anyString(), any(User.class)); }
@Test public void msgShouldReturnIfOneArgument() throws CommandException { parser.parse("/msg niles"); verify(messageController).showSystemMessage("/msg - missing arguments <nick> <msg>"); verify(controller, never()).sendPrivateMessage(anyString(), any(User.class)); }
@Test public void msgShouldReturnIfUserIsMe() throws CommandException { when(controller.getUser("MySelf")).thenReturn(me); parser.parse("/msg MySelf hello"); verify(messageController).showSystemMessage("/msg - no point in doing that!"); verify(controller, never()).sendPrivateMessage(anyString(), any(User.class)); }
@Test public void msgShouldReturnIfUserIsNotFound() throws CommandException { parser.parse("/msg NoOne hello"); verify(messageController).showSystemMessage("/msg - no such user 'NoOne'"); verify(controller, never()).sendPrivateMessage(anyString(), any(User.class)); }
@Test public void msgShouldReturnIfPrivateChatIsDisabled() throws CommandException { settings.setNoPrivateChat(true); setupSomeOne(); parser.parse("/msg SomeOne hello"); verify(messageController).showSystemMessage( "/msg - can't send private chat message when private chat is disabled"); verify(controller, never()).sendPrivateMessage(anyString(), any(User.class)); }
@Test public void msgShouldReturnIfUserHasNoPrivateChatPort() throws CommandException { final User someOne = setupSomeOne(); assertEquals(0, someOne.getPrivateChatPort()); parser.parse("/msg SomeOne hello"); verify(messageController).showSystemMessage("/msg - SomeOne can't receive private chat messages"); verify(controller, never()).sendPrivateMessage(anyString(), any(User.class)); }
@Test public void msgShouldSendWholePrivateMessageToUser() throws CommandException { final User someOne = setupSomeOne(); someOne.setPrivateChatPort(1000); parser.parse("/msg SomeOne hello there, how are you? "); verify(messageController).showPrivateOwnMessage(someOne, "hello there, how are you?"); verify(controller).sendPrivateMessage("hello there, how are you?", someOne); }
@Test public void msgShouldShowSystemMessageIfSendPrivateMessageFails() throws CommandException { final User someOne = setupSomeOne(); someOne.setPrivateChatPort(1000); doThrow(new CommandException("No message")).when(controller).sendPrivateMessage(anyString(), any(User.class)); parser.parse("/msg SomeOne hello"); verify(controller).sendPrivateMessage("hello", someOne); verify(messageController).showSystemMessage("No message"); }
@Test public void nickShouldReturnIfNoArguments() throws CommandException { parser.parse("/nick"); verify(messageController).showSystemMessage("/nick - missing argument <nick>"); verify(controller, never()).changeMyNick(anyString()); }
@Test public void nickShouldReturnIfNickIsUnchanged() throws CommandException { parser.parse("/nick MySelf"); verify(messageController).showSystemMessage("/nick - you are already called 'MySelf'"); verify(controller, never()).changeMyNick(anyString()); }
@Test public void nickShouldReturnIfNickIsInUse() throws CommandException { when(controller.isNickInUse("Other")).thenReturn(true); parser.parse("/nick Other"); verify(messageController).showSystemMessage("/nick - 'Other' is in use by someone else"); verify(controller, never()).changeMyNick(anyString()); }
@Test public void nickShouldReturnIfNickIsInvalid() throws CommandException { parser.parse("/nick @Boss"); verify(messageController).showSystemMessage("/nick - '@Boss' is not a valid nick name. (1-10 letters)"); verify(controller, never()).changeMyNick(anyString()); }
@Test public void nickShouldChangeNickNameAndShowSystemMessageAndUpdateUserInterface() throws CommandException { doAnswer(withSetNickNameOnMe()).when(controller).changeMyNick(anyString()); parser.parse("/nick NewNick"); verify(messageController).showSystemMessage("You changed nick to NewNick"); verify(controller).changeMyNick("NewNick"); verify(userInterface).showTopic(); }
@Test public void nickShouldShowSystemMessageIfNickChangeFails() throws CommandException { doThrow(new CommandException("No!")).when(controller).changeMyNick(anyString()); parser.parse("/nick NewNick"); verify(messageController).showSystemMessage("No!"); verify(controller).changeMyNick("NewNick"); }
@Test public void usersShouldListMeIfOnlyMeConnected() { parser.parse("/users"); verify(messageController).showSystemMessage("Users: MySelf"); }
@Test public void usersShouldListAllUserSeparatedWithComma() { userList.add(new User("Amy", 1)); userList.add(new User("Peter", 2)); userList.add(new User("Zelda", 3)); parser.parse("/users"); verify(messageController).showSystemMessage("Users: Amy, MySelf, Peter, Zelda"); }
@Test public void transfersShouldShowSystemMessageWhenNoActiveTransfers() { parser.parse("/transfers"); verify(messageController).showSystemMessage("File transfers: no active file transfers"); }
@Test public void transfersShouldShowSystemMessageWithActiveSender() { final FileSender fileSender = createFileSender(5, "image.png", 500L, 12, 80L, "Amy"); when(transferList.getFileSenders()).thenReturn(Arrays.asList(fileSender)); parser.parse("/transfers"); verify(messageController).showSystemMessage("File transfers:\n" + "- Sending:\n" + " #5 image.png [500.00KB] (12%, 80.00KB/s) to Amy"); }
@Test public void transfersShouldShowSystemMessageWithMultipleActiveSenders() { final FileSender fileSender1 = createFileSender(1, "video.mp4", 15000L, 44, 56L, "Amy"); final FileSender fileSender2 = createFileSender(2, "kou.png", 10L, 80, 5L, "Donald"); final FileSender fileSender3 = createFileSender(4, "radiohead.mp3", 3500L, 25, 103L, "Dolly"); when(transferList.getFileSenders()).thenReturn(Arrays.asList(fileSender1, fileSender2, fileSender3)); parser.parse("/transfers"); verify(messageController).showSystemMessage("File transfers:\n" + "- Sending:\n" + " #1 video.mp4 [14.65MB] (44%, 56.00KB/s) to Amy\n" + " #2 kou.png [10.00KB] (80%, 5.00KB/s) to Donald\n" + " #4 radiohead.mp3 [3.42MB] (25%, 103.00KB/s) to Dolly"); }