Package co.vendorflow.oss.maildrop.test
Class InMemoryMailSink
- java.lang.Object
-
- co.vendorflow.oss.maildrop.test.InMemoryMailSink
-
- All Implemented Interfaces:
MailSink
public final class InMemoryMailSink extends Object implements MailSink
An in-memory implementation ofMailSinkthat places messages into a list. This implementation is intended for testing purposes; it can be used for in-process testing by injecting this sink into the test case and examining the sent messages directly, or it can be used in integration testing by attaching an HTTP REST or similar endpoint to the output.- Author:
- Christopher Smith
-
-
Constructor Summary
Constructors Constructor Description InMemoryMailSink()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MailStatusdeliver(MailMessage message)Appends the supplied message to the queue.List<MailMessage>drainQueue()Atomically replace the queue with a new one and return the previous queue.List<MailMessage>getQueue()Provide a reference to the queue.
-
-
-
Method Detail
-
deliver
public MailStatus deliver(MailMessage message) throws MaildropException
Appends the supplied message to the queue. This method is synchronized withdrainQueue()so that each message will be drained exactly once.- Specified by:
deliverin interfaceMailSink- Throws:
MaildropException
-
getQueue
public List<MailMessage> getQueue()
Provide a reference to the queue. Access to this list is synchronized, but no guarantees are made about the visibility of specific messages. In particular, code reading the queue might miss messages that are delivered after a subsequent call todrainQueue(), and messages might be appended to this list after it is returned (potentially resulting inConcurrentModificationException). Applications that need consistent ordering should generally drain the list and, if needed, append it to another data structure.- Returns:
- a synchronized reference to the queue list
-
drainQueue
public List<MailMessage> drainQueue()
Atomically replace the queue with a new one and return the previous queue. This method is guaranteed to return all messages exactly once, and it is synchronized with thedeliver(MailMessage)method.- Returns:
- the queue as it appeared immediately before the call to this method
-
-