You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/06/03 19:54:38 UTC

svn commit: r411449 - in /james/server/trunk/src/test/org/apache/james/transport/matchers: AbstractRecipientIsTest.java RecipientIsRegexTest.java RecipientIsTest.java

Author: norman
Date: Sat Jun  3 10:54:37 2006
New Revision: 411449

URL: http://svn.apache.org/viewvc?rev=411449&view=rev
Log:
-refactoring for using abstract class

Added:
    james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractRecipientIsTest.java
Modified:
    james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java
    james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java

Added: james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractRecipientIsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractRecipientIsTest.java?rev=411449&view=auto
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractRecipientIsTest.java (added)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/AbstractRecipientIsTest.java Sat Jun  3 10:54:37 2006
@@ -0,0 +1,70 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation.                  *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you *
+ * may not use this file except in compliance with the License. You    *
+ * may obtain a copy of the License at:                                *
+ *                                                                     *
+ *     http://www.apache.org/licenses/LICENSE-2.0                      *
+ *                                                                     *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS,   *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     *
+ * implied.  See the License for the specific language governing       *
+ * permissions and limitations under the License.                      *
+ ***********************************************************************/
+
+package org.apache.james.transport.matchers;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+import javax.mail.MessagingException;
+
+import junit.framework.TestCase;
+
+import org.apache.james.test.mock.mailet.MockMail;
+import org.apache.james.test.mock.mailet.MockMailContext;
+import org.apache.james.test.mock.mailet.MockMatcherConfig;
+import org.apache.mailet.MailAddress;
+import org.apache.mailet.Matcher;
+
+public abstract class AbstractRecipientIsTest extends TestCase {
+
+    protected MockMail mockedMail;
+
+    protected Matcher matcher;
+
+    private MailAddress[] recipients;
+
+    public AbstractRecipientIsTest(String arg0)
+            throws UnsupportedEncodingException {
+        super(arg0);
+    }
+
+    protected void setRecipients(MailAddress[] recipients) {
+        this.recipients = recipients;
+    }
+
+    protected void setupMockedMail() {
+        mockedMail = new MockMail();
+        mockedMail.setRecipients(Arrays.asList(recipients));
+
+    }
+
+    protected void setupMatcher() throws MessagingException {
+        matcher = createMatcher();
+        MockMatcherConfig mci = new MockMatcherConfig("RecipientIs="
+                + getRecipientName(), new MockMailContext());
+        matcher.init(mci);
+    }
+
+    protected void setupAll() throws MessagingException {
+        setupMockedMail();
+        setupMatcher();
+    }
+
+    protected abstract String getRecipientName();
+
+    protected abstract Matcher createMatcher();
+}

Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java?rev=411449&r1=411448&r2=411449&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java Sat Jun  3 10:54:37 2006
@@ -18,26 +18,14 @@
 package org.apache.james.transport.matchers;
 
 import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
 import java.util.Collection;
 
 import javax.mail.MessagingException;
 
-import junit.framework.TestCase;
-
-import org.apache.james.test.mock.mailet.MockMail;
-import org.apache.james.test.mock.mailet.MockMailContext;
-import org.apache.james.test.mock.mailet.MockMatcherConfig;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.Matcher;
 
-public class RecipientIsRegexTest extends TestCase {
-
-    private MockMail mockedMail;
-
-    private Matcher matcher;
-
-    private MailAddress[] recipients;
+public class RecipientIsRegexTest extends AbstractRecipientIsTest {
 
     private String regex = ".*";
 
@@ -46,34 +34,17 @@
         super(arg0);
     }
 
-    private void setRecipients(MailAddress[] recipients) {
-        this.recipients = recipients;
-    }
-
     private void setRegex(String regex) {
         this.regex = regex;
     }
 
-    private void setupMockedMail() {
-        mockedMail = new MockMail();
-        mockedMail.setRecipients(Arrays.asList(recipients));
-
-    }
-
-    private void setupMatcher() throws MessagingException {
-        matcher = new RecipientIsRegex();
-        MockMatcherConfig mci = new MockMatcherConfig("RecipientIsRegex="
-                + regex, new MockMailContext());
-        matcher.init(mci);
-    }
-
     // test if the recipients get returned as matched
     public void testRegexIsMatchedAllRecipients() throws MessagingException {
         setRecipients(new MailAddress[] { new MailAddress(
                 "test@james.apache.org") });
         setRegex(".*@.*");
-        setupMockedMail();
-        setupMatcher();
+
+        setupAll();
 
         Collection matchedRecipients = matcher.match(mockedMail);
 
@@ -88,8 +59,8 @@
                 new MailAddress("test@james.apache.org"),
                 new MailAddress("test2@james.apache.org") });
         setRegex("^test@.*");
-        setupMockedMail();
-        setupMatcher();
+
+        setupAll();
 
         Collection matchedRecipients = matcher.match(mockedMail);
 
@@ -103,8 +74,8 @@
                 new MailAddress("test@james2.apache.org"),
                 new MailAddress("test2@james2.apache.org") });
         setRegex(".*\\+");
-        setupMockedMail();
-        setupMatcher();
+
+        setupAll();
 
         Collection matchedRecipients = matcher.match(mockedMail);
 
@@ -121,12 +92,10 @@
         setRecipients(new MailAddress[] {
                 new MailAddress("test@james2.apache.org"),
                 new MailAddress("test2@james2.apache.org") });
-
         setRegex(invalidRegex);
-        setupMockedMail();
 
         try {
-            setupMatcher();
+            setupAll();
             matchedRecipients = matcher.match(mockedMail);
         } catch (MessagingException m) {
             m.printStackTrace();
@@ -136,5 +105,13 @@
         assertNull(matchedRecipients);
         assertEquals(regexException, exception);
 
+    }
+
+    protected String getRecipientName() {
+        return regex;
+    }
+
+    protected Matcher createMatcher() {
+        return new RecipientIsRegex();
     }
 }

Modified: james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java?rev=411449&r1=411448&r2=411449&view=diff
==============================================================================
--- james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsTest.java Sat Jun  3 10:54:37 2006
@@ -18,48 +18,23 @@
 package org.apache.james.transport.matchers;
 
 import java.io.UnsupportedEncodingException;
-import java.util.Arrays;
 import java.util.Collection;
 
 import javax.mail.MessagingException;
 
-import junit.framework.TestCase;
-
-import org.apache.james.test.mock.mailet.MockMail;
-import org.apache.james.test.mock.mailet.MockMailContext;
-import org.apache.james.test.mock.mailet.MockMatcherConfig;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.Matcher;
 
-public class RecipientIsTest extends TestCase {
-    
-    private MockMail mockedMail;
-
-    private Matcher matcher;
+public class RecipientIsTest extends AbstractRecipientIsTest {
 
     private final String RECIPIENT_NAME = "test@james.apache.org";
 
-    private MailAddress[] recipients;
-
     public RecipientIsTest(String arg0) throws UnsupportedEncodingException {
         super(arg0);
     }
 
-    private void setRecipients(MailAddress[] recipients) {
-        this.recipients = recipients;
-    }
-
-    private void setupMockedMail() {
-        mockedMail = new MockMail();
-        mockedMail.setRecipients(Arrays.asList(recipients));
-
-    }
-
-    private void setupMatcher() throws MessagingException {
-        matcher = new RecipientIs();
-        MockMatcherConfig mci = new MockMatcherConfig("RecipientIs="
-                + RECIPIENT_NAME, new MockMailContext());
-        matcher.init(mci);
+    protected String getRecipientName() {
+        return RECIPIENT_NAME;
     }
 
     // test if the recipients get returned as matched
@@ -83,8 +58,7 @@
                 new MailAddress("test@james.apache.org"),
                 new MailAddress("test2@james.apache.org") });
 
-        setupMockedMail();
-        setupMatcher();
+        setupAll();
 
         Collection matchedRecipients = matcher.match(mockedMail);
 
@@ -104,5 +78,10 @@
         Collection matchedRecipients = matcher.match(mockedMail);
 
         assertEquals(matchedRecipients.size(), 0);
+    }
+
+    protected Matcher createMatcher() {
+        // TODO Auto-generated method stub
+        return new RecipientIs();
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org