Author: norman
Date: Sun Jun 11 07:23:36 2006
New Revision: 413450

URL: http://svn.apache.org/viewvc?rev=413450&view=rev
Log:
Throw exception on empty pattern.
Add junit test for this

Modified:
    
james/server/trunk/src/java/org/apache/james/transport/matchers/RecipientIsRegex.java
    
james/server/trunk/src/test/org/apache/james/transport/matchers/RecipientIsRegexTest.java

Modified: 
james/server/trunk/src/java/org/apache/james/transport/matchers/RecipientIsRegex.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/transport/matchers/RecipientIsRegex.java?rev=413450&r1=413449&r2=413450&view=diff
==============================================================================
--- 
james/server/trunk/src/java/org/apache/james/transport/matchers/RecipientIsRegex.java
 (original)
+++ 
james/server/trunk/src/java/org/apache/james/transport/matchers/RecipientIsRegex.java
 Sun Jun 11 07:23:36 2006
@@ -47,7 +47,7 @@
 
     public void init() throws javax.mail.MessagingException {
         String patternString = getCondition();
-        if (patternString == null) {
+        if ((patternString == null) || (patternString.equals("")) ) {
             throw new MessagingException("Pattern is missing");
         }
         

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=413450&r1=413449&r2=413450&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
 Sun Jun 11 07:23:36 2006
@@ -98,12 +98,29 @@
             setupAll();
             matchedRecipients = matcher.match(mockedMail);
         } catch (MessagingException m) {
-            m.printStackTrace();
             regexException = m.getMessage();
         }
 
         assertNull(matchedRecipients);
         assertEquals(regexException, exception);
+
+    }
+
+    // test if an exception was thrown cause the regex was invalid
+    public void testThrowExceptionWithEmptyPattern() throws MessagingException 
{
+        boolean catchException = false;
+
+        setRecipients(new MailAddress[] {
+                new MailAddress("[EMAIL PROTECTED]"),
+                new MailAddress("[EMAIL PROTECTED]") });
+        setRegex("");
+
+        try {
+            setupAll();
+        } catch (MessagingException m) {
+            catchException = true;
+        }
+        assertTrue(catchException);
 
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to