EchoHandler extends TextWebSocketHandler { @Override protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception { var msg = message.getPayload(); session.sendMessage(new TextMessage("RECEIVED: " + msg)); }  @Override void afterConnectionEstablished(WebSocketSession session);  }
@Test public void shouldEchoMessage() throws Exception { var mockSession = mock(WebSocketSession.class); var msg = new TextMessage("Hello World!"); handler.handleTextMessage(mockSession, msg); verify(mockSession, times(1)).sendMessage(eq(new TextMessage("RECEIVED: Hello World!"))); }