### Question:
WebSocketServerHandler extends AbstractWebSocketHandler { @Override public void handleMessage(WebSocketSession webSocketSession, WebSocketMessage<?> webSocketMessage) throws Exception { String upperCaseText = webSocketMessage.getPayload().toString().toUpperCase(); webSocketSession.sendMessage(new TextMessage(upperCaseText)); if (upperCaseText.equals("BYE")) { webSocketSession.close(); } }  @Override void handleMessage(WebSocketSession webSocketSession, WebSocketMessage<?> webSocketMessage);  }### Answer:
@Test public void handleMessageTest() throws Exception { WebSocketServerHandler handler = new WebSocketServerHandler(); WebSocketSession session = mock(WebSocketSession.class); handler.handleMessage(session, new TextMessage("text")); ArgumentCaptor<WebSocketMessage<?>> messageCaptor = ArgumentCaptor.forClass(WebSocketMessage.class); verify(session).sendMessage(messageCaptor.capture()); assertEquals("TEXT", messageCaptor.getValue().getPayload().toString()); }
@Test public void handleByeMessage() throws Exception { WebSocketServerHandler handler = new WebSocketServerHandler(); WebSocketSession session = mock(WebSocketSession.class); handler.handleMessage(session, new TextMessage("BYE")); ArgumentCaptor<WebSocketMessage<?>> messageCaptor = ArgumentCaptor.forClass(WebSocketMessage.class); verify(session).sendMessage(messageCaptor.capture()); assertEquals("BYE", messageCaptor.getValue().getPayload().toString()); verify(session, times(1)).close(); }