@Test public void shouldSendTwoStateIfDiferent() { session.receives( "<message from='other@domain/other' to='self@domain/res' type='chat'>" + "<active xmlns='http://jabber.org/protocol/chatstates'/></message>"); chatStateManager.setOwnState(ChatState.composing); chatStateManager.setOwnState(ChatState.pause); session.verifySent( "<message from='self@domain/res' to='other@domain/other' type='chat'>" + "<composing xmlns='http://jabber.org/protocol/chatstates'/></message>" + "<message from='self@domain/res' to='other@domain/other' type='chat'>" + "<pause xmlns='http://jabber.org/protocol/chatstates'/></message>"); }
@Test public void shouldStopAfterGone() { session.receives( "<message from='other@domain/other' to='self@domain/res' type='chat'><active /></message>"); session.receives( "<message from='other@domain/other' to='self@domain/res' type='chat'><gone /></message>"); chatStateManager.setOwnState(ChatStateManager.ChatState.composing); chatStateManager.setOwnState(ChatStateManager.ChatState.pause); session.verifySent("<message><active /></message>"); session.verifyNotSent("<message><composing /></message>"); session.verifyNotSent("<message><pause /></message>"); session.verifyNotSent("<message><gone /></message>"); }
@Before public void beforeTests() { session = new SessionTester(); chatManager = new PairChatManager(session); session.setLoggedIn(MYSELF); final StateManager stateManager = new StateManager(chatManager); chat = chatManager.open(OTHER); chatStateManager = stateManager.getChatState(chat); stateListener = new MockedListener<ChatState>(); chatStateManager.onChatStateChanged(stateListener); }
@Test public void shouldStartStateAfterNegotiation() { chat.send(new Message("test message")); session.receives( "<message from='other@domain/other' to='self@domain/res' type='chat'>" + "<active xmlns='http://jabber.org/protocol/chatstates'/></message>"); final Message message = new Message(MYSELF, OTHER, "test message"); message.addChild(ChatStateManager.ChatState.active.toString(), ChatStateManager.XMLNS); chatStateManager.setOwnState(ChatStateManager.ChatState.composing); session.verifySent( message.toString() + "<message from='self@domain/res' to='other@domain/other' type='chat'>" + "<composing xmlns='http://jabber.org/protocol/chatstates'/></message>"); }
@Test public void shouldNotSendStateIfNegotiationNotAccepted() { chatStateManager.setOwnState(ChatState.composing); session.verifySentNothing(); }