1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.james.transport.matchers;
22
23 import org.apache.mailet.base.test.FakeMail;
24 import org.apache.mailet.base.test.FakeMailContext;
25 import org.apache.mailet.base.test.FakeMatcherConfig;
26
27 import org.apache.mailet.MailAddress;
28 import org.apache.mailet.Matcher;
29
30 import javax.mail.MessagingException;
31
32 import java.io.UnsupportedEncodingException;
33 import java.util.Arrays;
34 import java.util.Collection;
35
36 import junit.framework.TestCase;
37
38 public class IsSingleRecipientTest extends TestCase {
39
40 private FakeMail mockedMail;
41
42 private Matcher matcher;
43
44 private MailAddress[] recipients;
45
46 public IsSingleRecipientTest(String arg0)
47 throws UnsupportedEncodingException {
48 super(arg0);
49 }
50
51 private void setRecipients(MailAddress[] recipients) {
52 this.recipients = recipients;
53 }
54
55 private void setupMockedMail() {
56 mockedMail = new FakeMail();
57 mockedMail.setRecipients(Arrays.asList(recipients));
58
59 }
60
61 private void setupMatcher() throws MessagingException {
62
63 matcher = new IsSingleRecipient();
64 FakeMatcherConfig mci = new FakeMatcherConfig("IsSingleRecipient",
65 new FakeMailContext());
66 matcher.init(mci);
67 }
68
69
70 public void testHostIsMatchedAllRecipients() throws MessagingException {
71 setRecipients(new MailAddress[] { new MailAddress(
72 "test@james.apache.org") });
73
74 setupMockedMail();
75 setupMatcher();
76
77 Collection matchedRecipients = matcher.match(mockedMail);
78
79 assertNotNull(matchedRecipients);
80 }
81
82
83 public void testHostIsMatchedOneRecipient() throws MessagingException {
84 setRecipients(new MailAddress[] {
85 new MailAddress("test@james2.apache.org"),
86 new MailAddress("test2@james.apache.org") });
87
88 setupMockedMail();
89 setupMatcher();
90
91 Collection matchedRecipients = matcher.match(mockedMail);
92
93 assertNull(matchedRecipients);
94 }
95
96 }