/** * Tests sendTopicChangeMessage(). * * Expects: 18102542!TOPIC#Christian:(Snoopy)[2132321323]Interesting changed topic */ @Test public void testSendTopicChangeMessage() { final Topic topic = new Topic("Interesting changed topic", "Snoopy", 2132321323L); final String message = "(" + topic.getNick() + ")" + "[" + topic.getTime() + "]" + topic.getTopic(); messages.sendTopicChangeMessage(topic); verify(service).sendMessageToAllUsers(createMessage("TOPIC") + message); }
/** * Changes the topic, and sends a notification to the other clients. * * @param newTopic The new topic to set. * @throws CommandException If there is no connection to the network, * or the application user is away, * or the topic is too long. */ public void changeTopic(final String newTopic) throws CommandException { if (!isLoggedOn()) { throw new CommandException(coreMessages.getMessage("core.topic.error.notConnected")); } else if (me.isAway()) { throw new CommandException(coreMessages.getMessage("core.topic.error.meIsAway")); } else if (Tools.getBytes(newTopic) > Constants.MESSAGE_MAX_BYTES) { throw new CommandException(coreMessages.getMessage("core.topic.error.messageTooLong", Constants.MESSAGE_MAX_BYTES)); } final long time = System.currentTimeMillis(); final Topic newTopicObj = new Topic(newTopic, me.getNick(), time); networkMessages.sendTopicChangeMessage(newTopicObj); final Topic topic = getTopic(); topic.changeTopic(newTopicObj); }
/** * Changes the topic, and sends a notification to the other clients. * * @param newTopic The new topic to set. * @throws CommandException If there is no connection to the network, * or the application user is away, * or the topic is too long. */ public void changeTopic(final String newTopic) throws CommandException { if (!isLoggedOn()) { throw new CommandException(coreMessages.getMessage("core.topic.error.notConnected")); } else if (me.isAway()) { throw new CommandException(coreMessages.getMessage("core.topic.error.meIsAway")); } else if (Tools.getBytes(newTopic) > Constants.MESSAGE_MAX_BYTES) { throw new CommandException(coreMessages.getMessage("core.topic.error.messageTooLong", Constants.MESSAGE_MAX_BYTES)); } final long time = System.currentTimeMillis(); final Topic newTopicObj = new Topic(newTopic, me.getNick(), time); networkMessages.sendTopicChangeMessage(newTopicObj); final Topic topic = getTopic(); topic.changeTopic(newTopicObj); }
@Test public void changeTopicShouldUpdateTopicAndSendTopicChangeMessage() throws CommandException { doReturn(true).when(controller).isLoggedOn(); controller.changeTopic("new topic"); final ArgumentCaptor<Topic> topicCaptor = ArgumentCaptor.forClass(Topic.class); verify(networkMessages).sendTopicChangeMessage(topicCaptor.capture()); final Topic messageTopic = topicCaptor.getValue(); final Topic controllerTopic = controller.getTopic(); assertEquals("new topic", messageTopic.getTopic()); assertEquals("new topic", controllerTopic.getTopic()); assertEquals(me.getNick(), messageTopic.getNick()); assertEquals(me.getNick(), controllerTopic.getNick()); assertTrue(DateTestUtils.isNow(new Date(messageTopic.getTime()))); assertEquals(messageTopic.getTime(), controllerTopic.getTime()); }