@Test public void testHandleMessageWithParams() throws Exception { when(player1Session.getBasicRemote()).thenReturn(player1Basic); when(player1Session.getUserProperties()).thenReturn(userProperties); when(player2Session.getBasicRemote()).thenReturn(player2Basic); when(userProperties.get(TicTacToeEndpoint.GAME_PROPERTY_KEY)).thenReturn(game); handler.handleMessage(player1Session, TicTacToeMessage.GAME_HAS_WINNER, "1", "2", "3"); verify(player1Basic).sendText("p4 1 2 3"); verify(player2Basic).sendText("p4 1 2 3"); }
@Test(expected = UnhandledMessageException.class) public void testHandleMessageSendFailure() throws Exception { when(player1Session.getBasicRemote()).thenReturn(player1Basic); when(player1Session.getUserProperties()).thenReturn(userProperties); when(player2Session.getBasicRemote()).thenReturn(player2Basic); when(userProperties.get(TicTacToeEndpoint.GAME_PROPERTY_KEY)).thenReturn(game); doThrow(new IOException()).when(player2Basic).sendText("p4"); try { handler.handleMessage(player1Session, TicTacToeMessage.GAME_HAS_WINNER); } catch (UnhandledMessageException e) { verify(player1Basic).sendText("p4"); verify(player2Basic).sendText("p4"); assertThat(e.getCause(), is(instanceOf(IOException.class))); throw e; } }