MessengerImpl implements Messenger, MessageProcessor { @Override public void sendMessage( final Peer peer, final Message message, final String recipient, final int timeToLive, final Map<String, String> headers ) throws MessageException { Preconditions.checkNotNull( peer, "Peer is null" ); Preconditions.checkNotNull( message, "Message is null" ); Preconditions.checkArgument( !StringUtils.isBlank( recipient ), "Invalid recipient" ); Preconditions.checkArgument( timeToLive > 0, "Invalid time-to-live" ); try { Envelope envelope = new Envelope( message, peer.getId(), recipient, timeToLive, headers ); messengerDataService.saveEnvelope( envelope ); } catch ( Exception e ) { LOG.error( "Error in sendMessage", e ); throw new MessageException( e ); } }  void init(); void destroy(); void setDaoManager( final DaoManager daoManager ); @Override Message createMessage( final Object payload ); @Override void sendMessage( final Peer peer, final Message message, final String recipient, final int timeToLive,
                             final Map<String, String> headers ); @Override MessageStatus getMessageStatus( final UUID messageId ); @Override void processMessage( String envelopeString ); void addMessageListener( final MessageListener listener ); void removeMessageListener( final MessageListener listener );  }
@Test( expected = MessageException.class ) public void testSendMessage() throws Exception { messenger.sendMessage( localPeer, message, RECIPIENT, TIME_TO_LIVE, HEADERS ); verify( messengerDataService ).saveEnvelope( isA( Envelope.class ) ); doThrow( new RuntimeException() ).when( messengerDataService ).saveEnvelope( any( Envelope.class ) ); messenger.sendMessage( localPeer, message, RECIPIENT, TIME_TO_LIVE, HEADERS ); }