/** * Tests sendBackMessage(). * * Expects: 12485102!BACK#Christian: */ @Test public void testSendBackMessage() { messages.sendBackMessage(); verify(service).sendMessageToAllUsers(createMessage("BACK")); }
@Test public void changeAwayStatusToBackWithMeShouldSendBackMessageAndChangeStatus() throws CommandException { when(controller.isLoggedOn()).thenReturn(true); final UserListController userListController = TestUtils.setFieldValueWithMock(controller, "userListController", UserListController.class); controller.changeAwayStatus(me.getCode(), false, ""); verify(networkMessages).sendBackMessage(); verify(userListController).changeAwayStatus(me.getCode(), false, ""); }
/** * Updates the away status and the away message for the user. * * @param code The user code for the user to update. * @param away If the user is away or not. * @param awaymsg The away message for that user. Will be trimmed. * @throws CommandException If there is no connection to the network, * or the user tries to set an away message that is to long. */ public void changeAwayStatus(final int code, final boolean away, final String awaymsg) throws CommandException { if (code == me.getCode() && !isLoggedOn()) { throw new CommandException(coreMessages.getMessage("core.away.error.notConnected")); } else if (Tools.getBytes(awaymsg) > Constants.MESSAGE_MAX_BYTES) { throw new CommandException(coreMessages.getMessage("core.away.error.awayMessageTooLong", Constants.MESSAGE_MAX_BYTES)); } final String trimmedAwayMessage = awaymsg.trim(); if (code == me.getCode()) { if (away) { networkMessages.sendAwayMessage(trimmedAwayMessage); } else { networkMessages.sendBackMessage(); } } userListController.changeAwayStatus(code, away, trimmedAwayMessage); }
/** * Updates the away status and the away message for the user. * * @param code The user code for the user to update. * @param away If the user is away or not. * @param awaymsg The away message for that user. Will be trimmed. * @throws CommandException If there is no connection to the network, * or the user tries to set an away message that is to long. */ public void changeAwayStatus(final int code, final boolean away, final String awaymsg) throws CommandException { if (code == me.getCode() && !isLoggedOn()) { throw new CommandException(coreMessages.getMessage("core.away.error.notConnected")); } else if (Tools.getBytes(awaymsg) > Constants.MESSAGE_MAX_BYTES) { throw new CommandException(coreMessages.getMessage("core.away.error.awayMessageTooLong", Constants.MESSAGE_MAX_BYTES)); } final String trimmedAwayMessage = awaymsg.trim(); if (code == me.getCode()) { if (away) { networkMessages.sendAwayMessage(trimmedAwayMessage); } else { networkMessages.sendBackMessage(); } } userListController.changeAwayStatus(code, away, trimmedAwayMessage); }