public class MockEmailTransport extends Transport
Transport
implementation that doesn't send any messages,
just queues them in its getSentMessages()
list
(useful for message-sending functional tests).Modifier and Type | Class and Description |
---|---|
static class |
MockEmailTransport.SentMessage
Container class for message sent through the mock transport.
|
Modifier and Type | Field and Description |
---|---|
protected List<MockEmailTransport.SentMessage> |
sentMessages |
Constructor and Description |
---|
MockEmailTransport()
Default constructor using the session default instance and a default
URLName . |
MockEmailTransport(Session session)
Constructor for using a specified session and a default
URLName |
MockEmailTransport(Session session,
URLName name)
Constructor for using a specified session and URLName.
|
Modifier and Type | Method and Description |
---|---|
static Transport |
getMockTransport()
Mock transport for
EmailDeliverer to use. |
List<MockEmailTransport.SentMessage> |
getSentMessages()
Active list of sent messages.
|
static boolean |
isUseMockTransport()
Determine if this
Transport is using a mock transport. |
protected boolean |
protocolConnect(String host,
int port,
String user,
String password)
The method to perform the actual protocol-specific connection attempt.
|
void |
sendMessage(Message message,
Address[] addresses)
Adds a sent message to the list of message sent through the mock transport.
|
static void |
setMockTransport(Transport transport)
Mock transport for
EmailDeliverer to use
(null to not use a mock transport). |
static void |
setUseMockTransport(boolean use)
Set if this
Transport is using a mock transport. |
addTransportListener, notifyTransportListeners, removeTransportListener, send, send, send, send
addConnectionListener, close, connect, connect, connect, connect, finalize, getURLName, isConnected, notifyConnectionListeners, queueEvent, removeConnectionListener, setConnected, setURLName, toString
protected List<MockEmailTransport.SentMessage> sentMessages
public MockEmailTransport()
URLName
.public MockEmailTransport(Session session)
URLName
session
- Session
object for this Transport.public static boolean isUseMockTransport()
Transport
is using a mock transport.EmailDeliverer
is using a mock transport. Otherwise false.public static void setUseMockTransport(boolean use)
public static Transport getMockTransport()
EmailDeliverer
to use.Transport
used for this class.public static void setMockTransport(Transport transport)
EmailDeliverer
to use
(null to not use a mock transport).transport
- A Transport
public void sendMessage(Message message, Address[] addresses) throws MessagingException
sendMessage
in class Transport
message
- The message
sent.addresses
- The array of address
contained in the message.MessagingException
protected boolean protocolConnect(String host, int port, String user, String password) throws MessagingException
protocolConnect
in class Service
host
- String ( ignored )port
- int ( ignored )user
- String ( ignored )password
- String ( ignored )MessagingException
public List<MockEmailTransport.SentMessage> getSentMessages()