/** * Updates the write state for the user. This is useful to see which * users are currently writing. * * If the user is the application user, messages will be sent to the * other clients to notify of changes. * * @param code The user code for the user to update. * @param writing True if the user is writing. */ public void changeWriting(final int code, final boolean writing) { userListController.changeWriting(code, writing); if (code == me.getCode()) { chatState.setWrote(writing); if (writing) { networkMessages.sendWritingMessage(); } else { networkMessages.sendStoppedWritingMessage(); } } }
/** * Updates the write state for the user. This is useful to see which * users are currently writing. * * If the user is the application user, messages will be sent to the * other clients to notify of changes. * * @param code The user code for the user to update. * @param writing True if the user is writing. */ public void changeWriting(final int code, final boolean writing) { userListController.changeWriting(code, writing); if (code == me.getCode()) { chatState.setWrote(writing); if (writing) { networkMessages.sendWritingMessage(); } else { networkMessages.sendStoppedWritingMessage(); } } }
/** * Tests sendStoppedWritingMessage(). * * Expects: 15140738!STOPPEDWRITING#Christian: */ @Test public void testSendStoppedWritingMessage() { messages.sendStoppedWritingMessage(); verify(service).sendMessageToAllUsers(createMessage("STOPPEDWRITING")); }
@Test public void updateMeWritingShouldUpdateMeAndNotifyOthersOnlyWhenStateChanges() { assertFalse(me.isWriting()); // Not writing - nothing happens controller.updateMeWriting(false); verifyZeroInteractions(networkMessages); assertFalse(me.isWriting()); // Wrote something - notify others and update me controller.updateMeWriting(true); verify(networkMessages).sendWritingMessage(); assertTrue(me.isWriting()); // Continues to write - nothing happens controller.updateMeWriting(true); verifyNoMoreInteractions(networkMessages); assertTrue(me.isWriting()); // Stopped writing - notify others and update me controller.updateMeWriting(false); verify(networkMessages).sendStoppedWritingMessage(); assertFalse(me.isWriting()); // Still not writing - nothing happens controller.updateMeWriting(false); verifyNoMoreInteractions(networkMessages); assertFalse(me.isWriting()); }