MessengerImpl implements Messenger, MessageProcessor { @Override public MessageStatus getMessageStatus( final UUID messageId ) throws MessageException { Preconditions.checkNotNull( messageId, "Invalid message id" ); try { Envelope envelope = messengerDataService.getEnvelope( messageId ); if ( envelope != null ) { if ( envelope.isSent() ) { return MessageStatus.SENT; } else if ( ( envelope.getCreateDate().getTime() + ( envelope.getTimeToLive() + 10 ) * 1000 ) > System .currentTimeMillis() ) { return MessageStatus.IN_PROCESS; } else { return MessageStatus.EXPIRED; } } return MessageStatus.NOT_FOUND; } catch ( Exception e ) { LOG.error( "Error in getMessageStatus", 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 testGetMessageStatus() throws Exception { Envelope envelope = mock( Envelope.class ); when( envelope.isSent() ).thenReturn( false ); MessageStatus status = messenger.getMessageStatus( MESSAGE_ID ); assertEquals( MessageStatus.NOT_FOUND, status ); when( messengerDataService.getEnvelope( MESSAGE_ID ) ).thenReturn( envelope ); when( envelope.getTimeToLive() ).thenReturn( TIME_TO_LIVE ); Timestamp createDate = mock( Timestamp.class ); when( envelope.getCreateDate() ).thenReturn( createDate ); when( createDate.getTime() ).thenReturn( System.currentTimeMillis() - 1000000 ); status = messenger.getMessageStatus( MESSAGE_ID ); assertEquals( MessageStatus.EXPIRED, status ); when( createDate.getTime() ).thenReturn( System.currentTimeMillis() + 1000000 ); status = messenger.getMessageStatus( MESSAGE_ID ); assertEquals( MessageStatus.IN_PROCESS, status ); when( envelope.isSent() ).thenReturn( true ); status = messenger.getMessageStatus( MESSAGE_ID ); assertEquals( MessageStatus.SENT, status ); doThrow( new RuntimeException() ).when( messengerDataService ).getEnvelope( any( UUID.class ) ); messenger.getMessageStatus( MESSAGE_ID ); }