MessengerDataService { public Set<Envelope> getEnvelopes() { Set<Envelope> result = Sets.newHashSet(); List<String> targetPeers = messageDao.getTargetPeers(); for ( final String targetPeer : targetPeers ) { List<MessageEntity> messages = messageDao.getMessages( targetPeer, WIDENING_INTERVAL_SEC, MESSAGE_LIMIT_PER_PEER ); Set<Envelope> envelopes = new HashSet<>(); envelopes.addAll( buildEnvelopes( messages ) ); result.addAll( envelopes ); } return result; } MessengerDataService( EntityManagerFactory entityManagerFactory ); void purgeExpiredMessages(); Set<Envelope> getEnvelopes(); void markAsSent( Envelope envelope ); void incrementDeliveryAttempts( Envelope envelope ); void saveEnvelope( Envelope envelope ); Envelope getEnvelope( UUID messageId );  }
@Test public void testGetEnvelopes() throws Exception { when( messageDao.getTargetPeers() ).thenReturn( Lists.newArrayList( TARGET_PEER_ID ) ); when( messageDao.getMessages( eq( TARGET_PEER_ID ), anyInt(), anyInt() ) ) .thenReturn( Lists.newArrayList( messageEntity ) ); Set<Envelope> envelopeSet = messengerDataService.getEnvelopes(); assertFalse( envelopeSet.isEmpty() ); }