RemotePeerMessageSender implements Callable<Boolean> { @Override public Boolean call() { WebClient client = null; try { client = getWebClient( targetPeer.getPeerInfo() ); for ( Envelope envelope : envelopes ) { Response response = null; try { response = client.post( JsonUtil.toJson( envelope ) ); WebClientBuilder.checkResponse( response, Response.Status.ACCEPTED ); messengerDataService.markAsSent( envelope ); } catch ( Exception e ) { messengerDataService.incrementDeliveryAttempts( envelope ); LOG.error( "Error in RemotePeerMessageSender", e ); break; } } return true; } catch ( Exception e ) { LOG.error( e.getMessage() ); } finally { WebClientBuilder.close( client ); } return false; } RemotePeerMessageSender( MessengerDataService messengerDataService, final Peer targetPeer, final Set<Envelope> envelopes ); @Override Boolean call();  }
@Test public void testCall() throws Exception { doReturn( response ).when( webClient ).post( anyString() ); doReturn( Response.Status.ACCEPTED.getStatusCode() ).when( response ).getStatus(); remotePeerMessageSender.call(); verify( webClient ).post( anyString() ); verify( messengerDataService ).markAsSent( envelope ); }
@Test public void testCallException() throws Exception { doThrow( new RuntimeException() ).when( webClient ).post( anyString() ); remotePeerMessageSender.call(); verify( messengerDataService ).incrementDeliveryAttempts( envelope ); }