1 package com.ozacc.mail.mailet;
3 import java.util.ArrayList;
6 import javax.mail.internet.InternetAddress;
8 import org.apache.log4j.BasicConfigurator;
10 import junit.framework.TestCase;
12 import com.ozacc.mail.fetch.ReceivedMail;
13 import com.ozacc.mail.mock.MockFetchMailPro;
16 * MailetRunnerのテストケース。
18 * @author Tomohiro Otsuka
19 * @version $Id: MailetRunnerTest.java,v 1.1.2.1 2005/02/06 13:53:54 otsuka Exp $
21 public class MailetRunnerTest extends TestCase {
23 private MailetRunner mailetRunner;
26 * @see TestCase#setUp()
28 protected void setUp() throws Exception {
30 BasicConfigurator.configure();
32 MockFetchMailPro fetchMailPro = new MockFetchMailPro();
33 fetchMailPro.setupGetMails(getSampleMails());
35 Mailet mailet = getSubjectOutputMailet();
36 Matcher matcher = getExampleComAddressMatcher();
37 List matcherList = new ArrayList();
38 matcherList.add(matcher);
39 MailetWrapper mw = new MailetWrapper(mailet, matcherList);
40 List mwList = new ArrayList();
44 mailetRunner = new MailetRunner();
45 mailetRunner.setFetchMailPro(fetchMailPro);
46 mailetRunner.setMailetWrapperList(mwList);
52 private ReceivedMail[] getSampleMails() {
53 List list = new ArrayList();
54 ReceivedMail m1 = new ReceivedMail();
55 m1.setSubject("m1 - 出力されます。");
56 m1.addTo("to@example.com");
58 ReceivedMail m2 = new ReceivedMail();
59 m2.setSubject("m2 - 出力されません。");
60 m2.addTo("to@example.net");
62 ReceivedMail m3 = new ReceivedMail();
63 m3.setSubject("m3 - 出力されます。");
64 m3.addTo("to@example.net");
65 m3.addTo("to@example.com");
67 return (ReceivedMail[])list.toArray(new ReceivedMail[list.size()]);
73 private Matcher getExampleComAddressMatcher() {
74 Matcher m = new Matcher() {
76 public boolean match(ReceivedMail mail) {
77 InternetAddress[] toAddresses = mail.getTo();
78 for (int i = 0; i < toAddresses.length; i++) {
79 InternetAddress address = toAddresses[i];
80 if (address.getAddress().equalsIgnoreCase("to@example.com")) {
93 private Mailet getSubjectOutputMailet() {
96 public void service(ReceivedMail mail) {
97 System.out.println(mail.getSubject());
103 * @see TestCase#tearDown()
105 protected void tearDown() throws Exception {
107 BasicConfigurator.resetConfiguration();
110 public void testRun() {