KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > james > transport > matchers > SenderIsTest


1 /****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one *
3  * or more contributor license agreements. See the NOTICE file *
4  * distributed with this work for additional information *
5  * regarding copyright ownership. The ASF licenses this file *
6  * to you under the Apache License, Version 2.0 (the *
7  * "License"); you may not use this file except in compliance *
8  * with the License. You may obtain a copy of the License at *
9  * *
10  * http://www.apache.org/licenses/LICENSE-2.0 *
11  * *
12  * Unless required by applicable law or agreed to in writing, *
13  * software distributed under the License is distributed on an *
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15  * KIND, either express or implied. See the License for the *
16  * specific language governing permissions and limitations *
17  * under the License. *
18  ****************************************************************/

19
20
21 package org.apache.james.transport.matchers;
22
23 import java.io.UnsupportedEncodingException JavaDoc;
24 import java.util.Collection JavaDoc;
25
26 import javax.mail.MessagingException JavaDoc;
27
28 import org.apache.mailet.MailAddress;
29 import org.apache.mailet.Matcher;
30
31 public class SenderIsTest extends AbstractSenderIsTest {
32
33     private final String JavaDoc SENDER_NAME = "test@james.apache.org";
34
35     public SenderIsTest(String JavaDoc arg0) throws UnsupportedEncodingException JavaDoc {
36         super(arg0);
37     }
38
39     // test if matched
40
public void testSenderIsMatchedAllRecipients() throws MessagingException JavaDoc {
41         setSender(new MailAddress(SENDER_NAME));
42
43         setupMockedMail();
44         setupMatcher();
45
46         Collection JavaDoc matchedRecipients = matcher.match(mockedMail);
47
48         assertNotNull(matchedRecipients);
49         assertEquals(matchedRecipients.size(), mockedMail.getRecipients()
50                 .size());
51     }
52
53     // test if not matched
54
public void testSenderIsNotMatchedAllRecipients() throws MessagingException JavaDoc {
55         setSender(new MailAddress("t@james.apache.org"));
56
57         setupMockedMail();
58         setupMatcher();
59
60         Collection JavaDoc matchedRecipients = matcher.match(mockedMail);
61
62         assertNull(matchedRecipients);
63     }
64
65     protected Matcher createMatcher() {
66         return new SenderIs();
67     }
68
69     protected String JavaDoc getConfigOption() {
70         return "SenderIs=";
71     }
72
73     protected String JavaDoc getConfigValue() {
74         return SENDER_NAME;
75     }
76 }
77
Popular Tags