01: /****************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one *
03: * or more contributor license agreements. See the NOTICE file *
04: * distributed with this work for additional information *
05: * regarding copyright ownership. The ASF licenses this file *
06: * to you under the Apache License, Version 2.0 (the *
07: * "License"); you may not use this file except in compliance *
08: * with the License. You may obtain a copy of the License at *
09: * *
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: ****************************************************************/package org.apache.james.transport.matchers;
19:
20: import org.apache.james.test.mock.mailet.MockMail;
21: import org.apache.james.test.mock.mailet.MockMailContext;
22: import org.apache.james.test.mock.mailet.MockMatcherConfig;
23:
24: import org.apache.mailet.MailAddress;
25: import org.apache.mailet.Matcher;
26:
27: import javax.mail.MessagingException;
28: import javax.mail.internet.ParseException;
29:
30: import java.io.UnsupportedEncodingException;
31: import java.util.Arrays;
32: import java.util.Collection;
33:
34: import junit.framework.TestCase;
35:
36: public class AllTest extends TestCase {
37:
38: private MockMail mockedMail;
39:
40: private Matcher matcher;
41:
42: public AllTest(String arg0) throws UnsupportedEncodingException {
43: super (arg0);
44: }
45:
46: private void setupMockedMail() throws ParseException {
47: mockedMail = new MockMail();
48: mockedMail.setRecipients(Arrays.asList(new MailAddress[] {
49: new MailAddress("test@james.apache.org"),
50: new MailAddress("test2@james.apache.org") }));
51:
52: }
53:
54: private void setupMatcher() throws MessagingException {
55: matcher = new All();
56: MockMatcherConfig mci = new MockMatcherConfig("All",
57: new MockMailContext());
58: matcher.init(mci);
59: }
60:
61: // test if all recipients was returned
62: public void testAllRecipientsReturned() throws MessagingException {
63: setupMockedMail();
64: setupMatcher();
65:
66: Collection matchedRecipients = matcher.match(mockedMail);
67:
68: assertNotNull(matchedRecipients);
69: assertEquals(matchedRecipients.size(), mockedMail
70: .getRecipients().size());
71: }
72:
73: }
|