You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by br...@apache.org on 2013/07/26 23:11:52 UTC

svn commit: r1507440 - /commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java

Author: britter
Date: Fri Jul 26 21:11:52 2013
New Revision: 1507440

URL: http://svn.apache.org/r1507440
Log:
No need for try/catch blocks. Correct exceptions can be verified via JUnit 4 annotation; mail server is stopped in tearDown of base class

Modified:
    commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java

Modified: commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java
URL: http://svn.apache.org/viewvc/commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java?rev=1507440&r1=1507439&r2=1507440&view=diff
==============================================================================
--- commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java (original)
+++ commons/proper/email/trunk/src/test/java/org/apache/commons/mail/EmailTest.java Fri Jul 26 21:11:52 2013
@@ -40,7 +40,9 @@ import javax.mail.internet.MimeMultipart
 import javax.mail.internet.ParseException;
 import org.apache.commons.mail.mocks.MockEmailConcrete;
 import org.junit.Before;
+import org.junit.Rule;
 import org.junit.Test;
+import org.junit.rules.ExpectedException;
 
 /**
  * JUnit test case for Email Class
@@ -144,8 +146,8 @@ public class EmailTest extends AbstractE
         assertTrue(
             Authenticator.class.isInstance(this.email.getAuthenticator()));
         assertEquals(
-            strUsername,
-            retrievedAuth.getPasswordAuthentication().getUserName());
+                strUsername,
+                retrievedAuth.getPasswordAuthentication().getUserName());
         assertEquals(
             strPassword,
             retrievedAuth.getPasswordAuthentication().getPassword());
@@ -283,9 +285,9 @@ public class EmailTest extends AbstractE
                 "joe.doe@apache.org",
                 "joe.doe@apache.org"));
         arrExpected.add(
-            new InternetAddress(
-                "someone_here@work-address.com.au",
-                "someone_here@work-address.com.au"));
+                new InternetAddress(
+                        "someone_here@work-address.com.au",
+                        "someone_here@work-address.com.au"));
 
         for (int i = 0; i < ARR_VALID_EMAILS.length; i++)
         {
@@ -1189,21 +1191,13 @@ public class EmailTest extends AbstractE
         }
     }
 
-    @Test
-    public void testSendNoHostName()
+    @Test(expected = EmailException.class)
+    public void testSendNoHostName() throws Exception
     {
-        try
-        {
-            this.getMailServer();
+        this.getMailServer();
 
-            this.email = new MockEmailConcrete();
-            this.email.send();
-            fail("Should have thrown an exception");
-        }
-        catch (EmailException e)
-        {
-            this.fakeMailServer.stop();
-        }
+        this.email = new MockEmailConcrete();
+        this.email.send();
     }
 
     @Test
@@ -1223,8 +1217,8 @@ public class EmailTest extends AbstractE
             this.email.addReplyTo("me@home.com");
 
             this.email.setContent(
-                "test string object",
-                " ; charset=" + EmailConstants.US_ASCII);
+                    "test string object",
+                    " ; charset=" + EmailConstants.US_ASCII);
 
             this.email.send();
             fail("Should have thrown an exception");
@@ -1236,66 +1230,44 @@ public class EmailTest extends AbstractE
         }
     }
 
-    @Test
-    public void testSendFromNotSet()
+    @Test(expected = EmailException.class)
+    public void testSendFromNotSet() throws Exception
     {
-        try
-        {
-            this.getMailServer();
+         this.getMailServer();
 
-            this.email = new MockEmailConcrete();
-            this.email.setHostName(this.strTestMailServer);
-            this.email.setSmtpPort(this.getMailServerPort());
+         this.email = new MockEmailConcrete();
+         this.email.setHostName(this.strTestMailServer);
+         this.email.setSmtpPort(this.getMailServerPort());
 
-            this.email.send();
-            fail("Should have thrown an exception");
-        }
-        catch (EmailException e)
-        {
-            this.fakeMailServer.stop();
-        }
+         this.email.send();
     }
 
-    @Test
-    public void testSendDestinationNotSet()
+    @Test(expected = EmailException.class)
+    public void testSendDestinationNotSet() throws Exception
     {
-        try
-        {
-            this.getMailServer();
+        this.getMailServer();
 
-            this.email = new MockEmailConcrete();
-            this.email.setHostName(this.strTestMailServer);
-            this.email.setSmtpPort(this.getMailServerPort());
-            this.email.setFrom("me@home.com");
-            this.email.send();
-            fail("Should have thrown an exception");
-        }
-        catch (EmailException e)
-        {
-            this.fakeMailServer.stop();
-        }
+        this.email = new MockEmailConcrete();
+        this.email.setHostName(this.strTestMailServer);
+        this.email.setSmtpPort(this.getMailServerPort());
+        this.email.setFrom("me@home.com");
+
+        this.email.send();
     }
 
-    @Test
-    public void testSendBadAuthSet()
+    @Test(expected = EmailException.class)
+    public void testSendBadAuthSet() throws Exception
     {
-        try
-        {
-            this.getMailServer();
+        this.getMailServer();
 
-            this.email = new MockEmailConcrete();
-            this.email.setHostName(this.strTestMailServer);
-            this.email.setSmtpPort(this.getMailServerPort());
-            this.email.setFrom(this.strTestMailFrom);
-            this.email.addTo(this.strTestMailTo);
-            this.email.setAuthentication(null, null);
-            this.email.send();
-            fail("Should have thrown an exception");
-        }
-        catch (EmailException e)
-        {
-            this.fakeMailServer.stop();
-        }
+        this.email = new MockEmailConcrete();
+        this.email.setHostName(this.strTestMailServer);
+        this.email.setSmtpPort(this.getMailServerPort());
+        this.email.setFrom(this.strTestMailFrom);
+        this.email.addTo(this.strTestMailTo);
+        this.email.setAuthentication(null, null);
+
+        this.email.send();
     }
 
     @Test