MessageResponseListener extends MessageListener implements Disposable { @Override public void onMessage( final Message message ) { MessageResponse messageResponse = message.getPayload( MessageResponse.class ); responses.put( messageResponse.getRequestId(), messageResponse, 5 * 1000L ); Semaphore semaphore = semaphoreMap.remove( messageResponse.getRequestId() ); if ( semaphore != null ) { semaphore.release(); } } MessageResponseListener( Messenger messenger ); @Override void dispose(); MessageResponse waitResponse( MessageRequest request, int requestTimeout, int responseTimeout ); @Override void onMessage( final Message message );  }
@Test public void testOnMessage() throws Exception { listener.onMessage( message ); verify( responses ).put( any( UUID.class ), eq( messageResponse ), anyLong() ); verify( semaphoreMap ).remove( any( UUID.class ) ); verify( semaphore ).release(); }