AgentWebSocket implements WebSocketListener { @Override public void onWebSocketBinary( byte[] payload, int offset, int len ) { this.logger.finest( "A binary message was received." ); try { Message msg = HttpSerializationUtils.deserializeObject( payload ); this.logger.finest( "The received message was deserialized as an instance of " + msg.getClass().getSimpleName()); this.messageQueue.add( msg ); } catch( ClassNotFoundException | IOException e ) { this.logger.severe( "A message could not be deserialized. => " + e.getClass().getSimpleName()); Utils.logException( this.logger, e ); this.messageQueue.errorWhileReceivingMessage(); } } AgentWebSocket( RoboconfMessageQueue messageQueue ); @Override void onWebSocketBinary( byte[] payload, int offset, int len ); @Override void onWebSocketClose( int statusCode, String reason ); @Override void onWebSocketConnect( Session session ); @Override void onWebSocketError( Throwable cause ); @Override void onWebSocketText( String message ); Session getSession();  }
@Test public void testBinaryMessageInError() { RoboconfMessageQueue messageQueue = new RoboconfMessageQueue(); AgentWebSocket socket = new AgentWebSocket( messageQueue ); socket.onWebSocketBinary( new byte[1], 0, 1 ); Assert.assertEquals( 0, messageQueue.size()); }