@Test public void resendAsynchronouslySeveralMessages() throws Exception { Map filterMap = Collections.singletonMap("state", "prepare_%"); MailStatus status1 = new MailStatus(); status1.setBatchId("batch1"); status1.setMessageId("message1"); MailStatus status2 = new MailStatus(); status2.setBatchId("batch2"); status2.setMessageId("message2"); List<MailStatus> statuses = new ArrayList<>(); statuses.add(status1); statuses.add(status2); MailStatusStore statusStore = this.mocker.getInstance(MailStatusStore.class, "database"); when(statusStore.load(filterMap, 0, 0, null, true)).thenReturn(statuses); MailContentStore contentStore = this.mocker.getInstance(MailContentStore.class, "filesystem"); ExtendedMimeMessage message1 = new ExtendedMimeMessage(); when(contentStore.load(any(), eq("batch1"), eq("message1"))).thenReturn(message1); ExtendedMimeMessage message2 = new ExtendedMimeMessage(); when(contentStore.load(any(), eq("batch2"), eq("message2"))).thenReturn(message2); MailSender sender = this.mocker.getInstance(MailSender.class); this.mocker.getComponentUnderTest().resendAsynchronously(filterMap, 0, 0); verify(sender).sendAsynchronously(eq(Arrays.asList(message1)), any(), any(MailListener.class)); verify(sender).sendAsynchronously(eq(Arrays.asList(message2)), any(), any(MailListener.class)); }
@Override public MailStatusResult resendAsynchronously(String batchId, String uniqueMessageId) throws MailStoreException { Session session = this.sessionFactory.create(Collections.singletonMap(SESSION_BATCHID_KEY, batchId)); MimeMessage message = loadMessage(session, batchId, uniqueMessageId); MailListener databaseMailListener = this.databaseMailListenerProvider.get(); this.mailSender.sendAsynchronously(Arrays.asList(message), session, databaseMailListener); return databaseMailListener.getMailStatusResult(); }
DatabaseMailResender implements MailResender { @Override public MailStatusResult resendAsynchronously(String batchId, String uniqueMessageId) throws MailStoreException { Session session = this.sessionFactory.create(Collections.singletonMap(SESSION_BATCHID_KEY, batchId)); MimeMessage message = loadMessage(session, batchId, uniqueMessageId); MailListener databaseMailListener = this.databaseMailListenerProvider.get(); this.mailSender.sendAsynchronously(Arrays.asList(message), session, databaseMailListener); return databaseMailListener.getMailStatusResult(); } }
DatabaseMailResender implements MailResender { @Override public MailStatusResult resendAsynchronously(String batchId, String uniqueMessageId) throws MailStoreException { Session session = this.sessionFactory.create(Collections.singletonMap(SESSION_BATCHID_KEY, batchId)); MimeMessage message = loadMessage(session, batchId, uniqueMessageId); MailListener databaseMailListener = this.databaseMailListenerProvider.get(); this.mailSender.sendAsynchronously(Arrays.asList(message), session, databaseMailListener); return databaseMailListener.getMailStatusResult(); }  }
DatabaseMailResender implements MailResender { @Override public MailStatusResult resendAsynchronously(String batchId, String uniqueMessageId) throws MailStoreException { Session session = this.sessionFactory.create(Collections.singletonMap(SESSION_BATCHID_KEY, batchId)); MimeMessage message = loadMessage(session, batchId, uniqueMessageId); MailListener databaseMailListener = this.databaseMailListenerProvider.get(); this.mailSender.sendAsynchronously(Arrays.asList(message), session, databaseMailListener); return databaseMailListener.getMailStatusResult(); }  @Override MailStatusResult resendAsynchronously(String batchId, String uniqueMessageId); @Override List<Pair<MailStatus, MailStatusResult>> resendAsynchronously(Map<String, Object> filterMap, int offset,
        int count); }
DatabaseMailResender implements MailResender { @Override public MailStatusResult resendAsynchronously(String batchId, String uniqueMessageId) throws MailStoreException { Session session = this.sessionFactory.create(Collections.singletonMap(SESSION_BATCHID_KEY, batchId)); MimeMessage message = loadMessage(session, batchId, uniqueMessageId); MailListener databaseMailListener = this.databaseMailListenerProvider.get(); this.mailSender.sendAsynchronously(Arrays.asList(message), session, databaseMailListener); return databaseMailListener.getMailStatusResult(); }  @Override MailStatusResult resendAsynchronously(String batchId, String uniqueMessageId); @Override List<Pair<MailStatus, MailStatusResult>> resendAsynchronously(Map<String, Object> filterMap, int offset,
        int count);  }