You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2022/11/12 18:49:48 UTC

[GitHub] [commons-email] garydgregory commented on a diff in pull request #106: JUnit5 assertThrows EmailTest

garydgregory commented on code in PR #106:
URL: https://github.com/apache/commons-email/pull/106#discussion_r1020793461


##########
src/test/java/org/apache/commons/mail/EmailTest.java:
##########
@@ -243,22 +246,25 @@ public void testGetSetSmtpPort()
                 Integer.parseInt(email.getSmtpPort()));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testSetSmtpPortZero()
     {
-        email.setSmtpPort(0);
+        final Executable testMethod = () -> email.setSmtpPort(0);
+        assertThrows(IllegalArgumentException.class, testMethod);

Review Comment:
   Hello @nhojpatrick 
   Thank you for your PR.
   As with the other PRs, the local variable is superfluous. 
   Please rebase on master to fix the spotbugs build on Java 11 and 17.



##########
src/test/java/org/apache/commons/mail/EmailTest.java:
##########
@@ -338,9 +344,10 @@ public void testSetFrom2() throws Exception
         }
     }
 
-    @Test(expected = IllegalCharsetNameException.class)
-    public void testSetFromBadEncoding() throws Exception {
-        email.setFrom("me@home.com", "me@home.com", "bad.encoding\uc5ec\n");
+    @Test
+    public void testSetFromBadEncoding() {
+        final Executable testMethod = () -> email.setFrom("me@home.com", "me@home.com", "bad.encoding\uc5ec\n");
+        assertThrows(IllegalCharsetNameException.class, testMethod);

Review Comment:
   Ditto



##########
src/test/java/org/apache/commons/mail/EmailTest.java:
##########
@@ -243,22 +246,25 @@ public void testGetSetSmtpPort()
                 Integer.parseInt(email.getSmtpPort()));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testSetSmtpPortZero()
     {
-        email.setSmtpPort(0);
+        final Executable testMethod = () -> email.setSmtpPort(0);
+        assertThrows(IllegalArgumentException.class, testMethod);
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testSetSmptPortNegative()
     {
-        email.setSmtpPort(-1);
+        final Executable testMethod = () -> email.setSmtpPort(-1);
+        assertThrows(IllegalArgumentException.class, testMethod);
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testSetSmtpPortMinValue()
     {
-        email.setSmtpPort(Integer.MIN_VALUE);
+        final Executable testMethod = () -> email.setSmtpPort(Integer.MIN_VALUE);
+        assertThrows(IllegalArgumentException.class, testMethod);

Review Comment:
   Ditto



##########
src/test/java/org/apache/commons/mail/EmailTest.java:
##########
@@ -243,22 +246,25 @@ public void testGetSetSmtpPort()
                 Integer.parseInt(email.getSmtpPort()));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testSetSmtpPortZero()
     {
-        email.setSmtpPort(0);
+        final Executable testMethod = () -> email.setSmtpPort(0);
+        assertThrows(IllegalArgumentException.class, testMethod);
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testSetSmptPortNegative()
     {
-        email.setSmtpPort(-1);
+        final Executable testMethod = () -> email.setSmtpPort(-1);
+        assertThrows(IllegalArgumentException.class, testMethod);

Review Comment:
   Ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org