RoboconfConsumer extends DefaultConsumer implements Consumer { @Override public void handleDelivery( String consumerTag, Envelope envelope, BasicProperties properties, byte[] body ) throws IOException { try { Message message = SerializationUtils.deserializeObject( body ); this.logger.finer( this.sourceName + " received a message " + message.getClass().getSimpleName() + " on routing key '" + envelope.getRoutingKey() + "'."); this.messageQueue.add( message ); } catch( ClassNotFoundException | IOException e ) { this.logger.severe( this.sourceName + ": a message could not be deserialized. => " + e.getClass().getSimpleName()); Utils.logException( this.logger, e ); this.messageQueue.errorWhileReceivingMessage(); } } RoboconfConsumer( String sourceName, Channel channel, RoboconfMessageQueue messageQueue ); @Override void handleDelivery( String consumerTag, Envelope envelope, BasicProperties properties, byte[] body ); @Override void handleShutdownSignal( String consumerTag, ShutdownSignalException sig ); @Override void handleCancelOk( String consumerTag ); @Override void handleCancel( String consumerTag );  }
@Test public void testHandleDeliveryWithDeserializationError() throws Exception { RoboconfMessageQueue messageQueue = new RoboconfMessageQueue(); Channel channel = Mockito.mock( Channel.class ); RoboconfConsumer rc = new RoboconfConsumer( "DM", channel, messageQueue ); final StringHandler logHandler = new StringHandler(); Logger logger = TestUtils.getInternalField( rc, "logger", Logger.class ); logger.setUseParentHandlers( false ); logger.addHandler( logHandler ); rc.handleDelivery( "tag", Mockito.mock( Envelope.class ), null, new byte[ 1 ]); Assert.assertTrue( logHandler.getLogs().startsWith( "DM: a message could not be deserialized." )); }