### Question:
JettyWebSocketHandler extends EngineIoWebSocket implements WebSocketListener { @Override public void onWebSocketBinary(byte[] payload, int offset, int len) { byte[] message; if((offset == 0) && (len == payload.length)) { message = payload; } else { message = new byte[len]; System.arraycopy(payload, offset, message, 0, len); } emit("message", (Object) message); } @SuppressWarnings("WeakerAccess")  JettyWebSocketHandler(EngineIoServer server); @Override Map<String, String> getQuery(); @Override void write(String message); @Override void write(byte[] message); @Override void close(); @Override void onWebSocketConnect(Session session); @Override void onWebSocketClose(int statusCode, String reason); @Override void onWebSocketError(Throwable cause); @Override void onWebSocketBinary(byte[] payload, int offset, int len); @Override void onWebSocketText(String message);  }### Answer:
@Test public void testOnMessage_binary_full() { final byte[] message = new byte[16]; (new Random()).nextBytes(message); final EngineIoServer server = new EngineIoServer(); final JettyWebSocketHandler handler = Mockito.spy(new JettyWebSocketHandler(server)); handler.onWebSocketBinary(message, 0, message.length); Mockito.verify(handler, Mockito.times(1)) .emit(Mockito.eq("message"), (Object) Mockito.eq(message)); }
@Test public void testOnMessage_binary_partial() { final byte[] message = new byte[16]; (new Random()).nextBytes(message); final byte[] messagePart = new byte[10]; final int offset = 3; System.arraycopy(message, offset, messagePart, 0, messagePart.length); final EngineIoServer server = new EngineIoServer(); final JettyWebSocketHandler handler = Mockito.spy(new JettyWebSocketHandler(server)); handler.onWebSocketBinary(message, offset, messagePart.length); Mockito.verify(handler, Mockito.times(1)) .emit(Mockito.eq("message"), (Object) Mockito.eq(messagePart)); }