com.ozacc.mail.mock.MockFetchMail Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ozacc-mail Show documentation
Show all versions of ozacc-mail Show documentation
Library to send and receive emails.
The newest version!
package com.ozacc.mail.mock;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.ozacc.mail.MailException;
import com.ozacc.mail.fetch.FetchMail;
import com.ozacc.mail.fetch.ReceivedMail;
/**
* FetchMailImplクラスのMock。
* setupGetMails()
メソッドでReceivedMail
インスタンスをセットすると、getMails()
メソッドがそのインスタンスを返します。
*
* @since 1.2
* @author Tomohiro Otsuka
* @version $Id: MockFetchMail.java,v 1.1.2.3 2005/02/05 09:25:25 otsuka Exp $
*/
public class MockFetchMail implements FetchMail {
private static Log log = LogFactory.getLog(MockFetchMail.class);
/** デフォルトのSMTPサーバ。「localhost」 */
public static final String DEFAULT_HOST = "localhost";
/** デフォルトのプロトコル。「pop3」 */
public static final String DEFAULT_PROTOCOL = "pop3";
/**
* デフォルトのポート。「-1」
* -1はプロトコルに応じた適切なポートを設定する特別な値。
*/
public static final int DEFAULT_PORT = -1;
private String host = DEFAULT_HOST;
private String protocol = DEFAULT_PROTOCOL;
private int port = DEFAULT_PORT;
private String username;
private String password;
private List receivedMails;
/**
* コンストラクタ。
*/
public MockFetchMail() {
super();
receivedMails = new ArrayList<>();
}
/**
* MockFetchMail
のgetMails()
メソッドが返す
* ReceivedMail
インスタンスをセットします。
*
* @param mail getMails()
メソッドが返すReceivedMail
インスタンス
*/
public void setupGetMails(ReceivedMail mail) {
receivedMails.add(mail);
}
/**
* MockFetchMail
のgetMails()
メソッドが返す
* ReceivedMail
インスタンスをセットします。
*
* @param mails getMails()
メソッドが返すReceivedMail
インスタンス配列
*/
public void setupGetMails(ReceivedMail[] mails) {
for (int i = 0; i < mails.length; i++) {
ReceivedMail mail = mails[i];
setupGetMails(mail);
}
}
/**
* @see com.ozacc.mail.fetch.FetchMail#getMails()
*/
public ReceivedMail[] getMails() throws MailException {
log.debug(protocol.toUpperCase() + "サーバ[" + host + "]に接続しるフリ。");
log.debug(protocol.toUpperCase() + "サーバ[" + host + "]に接続したフリ。");
if (!receivedMails.isEmpty()) {
log.debug(receivedMails.size() + "通のメールを受信するフリ。");
} else {
log.debug("受信するフリをするメールはありません。");
}
try {
return receivedMails.toArray(new ReceivedMail[receivedMails.size()]);
} finally {
log.debug(protocol.toUpperCase() + "サーバ[" + host + "]との接続を切断するフリ。");
log.debug(protocol.toUpperCase() + "サーバ[" + host + "]との接続を切断したフリ。");
}
}
/**
* @see com.ozacc.mail.fetch.FetchMail#getMails(boolean)
*/
public ReceivedMail[] getMails(boolean delete) throws MailException {
ReceivedMail[] result = getMails();
if (delete) {
receivedMails.clear();
}
return result;
}
/**
* @return Returns the host.
*/
public String getHost() {
return host;
}
/**
* @param host The host to set.
*/
public void setHost(String host) {
this.host = host;
}
/**
* @return Returns the password.
*/
public String getPassword() {
return password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return Returns the port.
*/
public int getPort() {
return port;
}
/**
* @param port The port to set.
*/
public void setPort(int port) {
this.port = port;
}
/**
* @return Returns the protocol.
*/
public String getProtocol() {
return protocol;
}
/**
* @param protocol The protocol to set.
*/
public void setProtocol(String protocol) {
this.protocol = protocol;
}
/**
* @return Returns the username.
*/
public String getUsername() {
return username;
}
/**
* @param username The username to set.
*/
public void setUsername(String username) {
this.username = username;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy