Author: henning
Date: Wed Sep  7 03:16:00 2005
New Revision: 279290

URL: http://svn.apache.org/viewcvs?rev=279290&view=rev
Log:
Added Niall's Unit test for invalid addresses. Thanks.


Added:
    
jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/InvalidAddressTest.java
   (with props)
Modified:
    jakarta/commons/proper/email/trunk/xdocs/changes.xml

Added: 
jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/InvalidAddressTest.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/InvalidAddressTest.java?rev=279290&view=auto
==============================================================================
--- 
jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/InvalidAddressTest.java
 (added)
+++ 
jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/InvalidAddressTest.java
 Wed Sep  7 03:16:00 2005
@@ -0,0 +1,194 @@
+/*
+ * Copyright 2005 The Apache Software Foundation
+ *
+ * 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.commons.mail;
+
+import org.apache.commons.mail.mocks.MockEmailConcrete;
+
+/**
+ * JUnit test case for invalid Addresses in Email Class
+ *
+ * @since 1.0
+ * @author Niall Pemberton
+ * @version $Id$
+ */
+public class InvalidAddressTest
+        extends BaseEmailTestCase
+{
+    /** */
+    private MockEmailConcrete email = null;
+
+    /** */
+    private static final String [] ARR_INVALID_EMAILS = {
+        "local [EMAIL PROTECTED]",
+        "local([EMAIL PROTECTED]",
+        "local)[EMAIL PROTECTED]",
+        "local<[EMAIL PROTECTED]",
+        "local>[EMAIL PROTECTED]",
+        "local,[EMAIL PROTECTED]",
+        "local;[EMAIL PROTECTED]",
+        "local:[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+
+        //      "local\"[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED] com",
+        "[EMAIL PROTECTED](com",
+        "[EMAIL PROTECTED])com",
+        "[EMAIL PROTECTED]<com",
+        "[EMAIL PROTECTED]>com",
+        "[EMAIL PROTECTED],com",
+        "[EMAIL PROTECTED];com",
+        "[EMAIL PROTECTED]:com",
+
+        //      "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "[EMAIL PROTECTED]",
+        "local.name@",
+        "@domain.com"
+    };
+
+    /**
+     * @param name name
+     */
+    public InvalidAddressTest(String name)
+    {
+        super(name);
+    }
+
+    /** */
+    protected void setUp()
+    {
+        super.setUp();
+
+        // reusable objects to be used across multiple tests
+        this.email = new MockEmailConcrete();
+    }
+
+    /**
+     *
+     * @throws Exception Exception
+     */
+    public void testSetInvalidFrom()
+            throws Exception
+    {
+        // ====================================================================
+        // Test setting invalid 'from' addresses
+        // ====================================================================
+        for (int i = 0; i < ARR_INVALID_EMAILS.length; i++)
+        {
+            try
+            {
+                // set from
+                email.setFrom(ARR_INVALID_EMAILS[i]);
+
+                // Expected an exception to be thrown
+                fail("setFrom " + i + " passed: " + ARR_INVALID_EMAILS[i]);
+            }
+            catch (EmailException ignore)
+            {
+                // Expected Result
+            }
+        }
+    }
+
+    /**
+     *
+     * @throws Exception Exception
+     */
+    public void testAddInvalidTo()
+            throws Exception
+    {
+        // ====================================================================
+        // Test adding invalid 'to' addresses
+        // ====================================================================
+        for (int i = 0; i < ARR_INVALID_EMAILS.length; i++)
+        {
+            try
+            {
+                // Add To
+                email.addTo(ARR_INVALID_EMAILS[i], "Joe");
+
+                // Expected an exception to be thrown
+                fail("addTo " + i + " passed: " + ARR_INVALID_EMAILS[i]);
+            }
+            catch (EmailException ignore)
+            {
+                // Expected Result
+            }
+        }
+    }
+
+    /**
+     *
+     * @throws Exception Exception
+     */
+    public void testAddInvalidCc()
+            throws Exception
+    {
+        // ====================================================================
+        // Test adding invalid 'cc' addresses
+        // ====================================================================
+        for (int i = 0; i < ARR_INVALID_EMAILS.length; i++)
+        {
+            try
+            {
+                // add cc
+                email.addCc(ARR_INVALID_EMAILS[i], "Joe");
+
+                // Expected an exception to be thrown
+                fail("addCc " + i + " passed: " + ARR_INVALID_EMAILS[i]);
+            }
+            catch (EmailException ignore)
+            {
+                // Expected Result
+            }
+        }
+    }
+
+    /**
+     *
+     * @throws Exception Exception
+     */
+    public void testAddInvalidBcc()
+            throws Exception
+    {
+        // ====================================================================
+        // Test adding invalid 'Bcc' addresses
+        // ====================================================================
+        for (int i = 0; i < ARR_INVALID_EMAILS.length; i++)
+        {
+            try
+            {
+                // add bcc
+                email.addBcc(ARR_INVALID_EMAILS[i], "Joe");
+
+                // Expected an exception to be thrown
+                fail("addBcc " + i + " passed: " + ARR_INVALID_EMAILS[i]);
+            }
+            catch (EmailException ignore)
+            {
+                // Expected Result
+            }
+        }
+    }
+}

Propchange: 
jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/InvalidAddressTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
jakarta/commons/proper/email/trunk/src/test/org/apache/commons/mail/InvalidAddressTest.java
------------------------------------------------------------------------------
    svn:keywords = Id Author

Modified: jakarta/commons/proper/email/trunk/xdocs/changes.xml
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/proper/email/trunk/xdocs/changes.xml?rev=279290&r1=279289&r2=279290&view=diff
==============================================================================
--- jakarta/commons/proper/email/trunk/xdocs/changes.xml (original)
+++ jakarta/commons/proper/email/trunk/xdocs/changes.xml Wed Sep  7 03:16:00 
2005
@@ -22,6 +22,9 @@
 
   <body>
     <release version="1.0-rc8-SNAPSHOT" date="in Subversion">
+      <action dev="henning" type="update" due-to="Niall Pemberton" 
issue="36535">
+        Add an unit test to check for invalid addresses.
+      </action>
       <action dev="henning" type="update" due-to="Stephen Colebourne" 
issue="36486">
         Remove dependencies to commons-lang, allowing commons-email to exist 
without
         any external dependencies in an J2EE 1.4+ environment.



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

Reply via email to