OfframpWebSocketHandler extends AbstractWebSocketHandler { @Override protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception { if (message.getPayloadLength() == 0) { log.warn("Road: {}, stream: {}, sessionId: {} - Ignoring message with zero sized payload", roadName, streamName, sessionId); return; } service.onEvent(new String(message.getPayload().array(), UTF_8)); }  @Override void afterConnectionEstablished(WebSocketSession session); @Override void afterConnectionClosed(WebSocketSession session, CloseStatus status); @Override void handleTransportError(WebSocketSession session, Throwable exception);  }
@Test public void handleBinaryMessage() throws Exception { Message<String> message = new Message<>(0, 1L, 1, 1L, "a"); BinaryMessage binaryMessage = new BinaryMessage((new ObjectMapper()).writeValueAsBytes(message)); String refUtf8 = new String(binaryMessage.getPayload().array(), UTF_8); String refUtf16 = new String(binaryMessage.getPayload().array(), UTF_16); underTest.afterConnectionEstablished(session); underTest.handleBinaryMessage(session, binaryMessage); ArgumentCaptor<String> valueCapture = ArgumentCaptor.forClass(String.class); verify(service).onEvent(valueCapture.capture()); String out = valueCapture.getValue(); assertEquals(refUtf8, out); assertNotEquals(refUtf16, out); }