CommandRequestListener extends RequestListener { @Override public Object onRequest( final Payload payload ) { final CommandRequest commandRequest = payload.getMessage( CommandRequest.class ); if ( commandRequest != null ) { try { Peer sourcePeer = getPeerManager().getPeer( payload.getSourcePeerId() ); LocalPeer localPeer = getPeerManager().getLocalPeer(); Host host = localPeer.findHost( commandRequest.getHostId() ); localPeer.executeAsync( commandRequest.getRequestBuilder(), host, new CommandRequestCallback( commandRequest, sourcePeer ) ); } catch ( Exception e ) { LOG.error( "Error in onMessage", e ); } } else { LOG.warn( "Null request" ); } return null; } CommandRequestListener(); @Override Object onRequest( final Payload payload );  }
@Test public void testOnRequest() throws Exception { listener.onRequest( payload ); verify( localPeer ).executeAsync( any( RequestBuilder.class ), eq( host ), any( CommandCallback.class ) ); doThrow( exception ).when( localPeer ) .executeAsync( any( RequestBuilder.class ), eq( host ), any( CommandCallback.class ) ); listener.onRequest( payload ); verify( exception ).printStackTrace( any( PrintStream.class ) ); when( payload.getMessage( CommandRequest.class ) ).thenReturn( null ); listener.onRequest( payload ); verify( peerManager, times( 2 ) ).getPeer( any( String.class ) ); }