You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/12/10 20:40:09 UTC

(commons-email) branch master updated: Complete half-baked test DataSourceUrlResolverTest.testResolvingHttpNonLenient()

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-email.git


The following commit(s) were added to refs/heads/master by this push:
     new bd2e0ea  Complete half-baked test DataSourceUrlResolverTest.testResolvingHttpNonLenient()
bd2e0ea is described below

commit bd2e0ea8482d403ec8b182f7108777872e9883f8
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 10 15:40:05 2023 -0500

    Complete half-baked test
    DataSourceUrlResolverTest.testResolvingHttpNonLenient()
---
 src/changes/changes.xml                            |  1 +
 .../mail/resolver/DataSourceUrlResolverTest.java   | 35 ++++++++++------------
 2 files changed, 16 insertions(+), 20 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index c2b5233..a3b1b09 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -45,6 +45,7 @@
       <action type="fix" dev="ggregory" due-to="Amir Behnam, Michael Osipov">Throw more specific exceptions in MimeMessageParser #11.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Email.setMailSession(Session) throws the more precise exception NullPointerException.</action>
       <action type="fix" dev="ggregory" due-to="Gary Gregory">Avoid possible NullPointerException in DataSourceClassPathResolver.resolve(String, boolean).</action>
+      <action type="fix" dev="ggregory" due-to="Gary Gregory">Complete half-baked test DataSourceUrlResolverTest.testResolvingHttpNonLenient().</action>
       <!-- ADD -->
       <action type="add" due-to="Dependabot" dev="ggregory">
         Add github/codeql-action #75.
diff --git a/src/test/java/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java b/src/test/java/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java
index 873305b..d74bfa6 100644
--- a/src/test/java/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java
+++ b/src/test/java/org/apache/commons/mail/resolver/DataSourceUrlResolverTest.java
@@ -16,32 +16,31 @@
  */
 package org.apache.commons.mail.resolver;
 
-import static org.junit.Assert.*;
-
-import org.apache.commons.mail.DataSourceResolver;
-import org.junit.Test;
+import static org.junit.Assert.assertNull;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
 
+import org.apache.commons.mail.DataSourceResolver;
+import org.junit.jupiter.api.Test;
+
 /**
  * JUnit test case for DataSourceUrlResolver.
  *
  * @since 1.3
  */
-public class DataSourceUrlResolverTest extends AbstractDataSourceResolverTest
-{
+public class DataSourceUrlResolverTest extends AbstractDataSourceResolverTest {
 
     /**
-     * Shows how the DataSourceUrlResolver can resolve files as well but this should
-     * be done using a DataSourceFileResolver.
+     * Shows how the DataSourceUrlResolver can resolve files as well but this should be done using a DataSourceFileResolver.
      *
      * @throws Exception the test failed
      */
     @Test
-    public void testResolvingFilesLenient() throws Exception
-    {
+    public void testResolvingFilesLenient() throws Exception {
         final DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new File("./src/test/resources").toURI().toURL(), true);
         assertTrue(toByteArray(dataSourceResolver.resolve("images/asf_logo_wide.gif")).length == IMG_SIZE);
         assertTrue(toByteArray(dataSourceResolver.resolve("./images/asf_logo_wide.gif")).length == IMG_SIZE);
@@ -55,8 +54,7 @@ public class DataSourceUrlResolverTest extends AbstractDataSourceResolverTest
      * @throws Exception the test failed
      */
     @Test
-    public void testResolvingHttpLenient() throws Exception
-    {
+    public void testResolvingHttpLenient() throws Exception {
         final DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new URL("https://www.apache.org"), true);
         assertTrue(toByteArray(dataSourceResolver.resolve("https://www.apache.org/images/feather-small.gif")).length > 1);
         assertTrue(toByteArray(dataSourceResolver.resolve("images/feather-small.gif")).length > 1);
@@ -70,8 +68,7 @@ public class DataSourceUrlResolverTest extends AbstractDataSourceResolverTest
      * @throws Exception the test failed
      */
     @Test
-    public void testResolvingHttpLenientHost() throws Exception
-    {
+    public void testResolvingHttpLenientHost() throws Exception {
         final DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new URL("http://does.not.exist"), true);
         assertNull(toByteArray(dataSourceResolver.resolve("/images/does-not-exist.gif")));
     }
@@ -81,13 +78,11 @@ public class DataSourceUrlResolverTest extends AbstractDataSourceResolverTest
      *
      * @throws Exception the test failed
      */
-    @Test(expected = IOException.class)
-    public void testResolvingHttpNonLenient() throws Exception
-    {
+    @Test
+    public void testResolvingHttpNonLenient() throws Exception {
         final DataSourceResolver dataSourceResolver = new DataSourceUrlResolver(new URL("http://does.not.exist"), false);
-        assertNotNull(dataSourceResolver.resolve("images/asf_logo_wide.gif"));
-
-        dataSourceResolver.resolve("images/does-not-exist.gif");
+        assertThrows(IOException.class, () -> dataSourceResolver.resolve("images/asf_logo_wide.gif"));
+        assertThrows(IOException.class, () -> dataSourceResolver.resolve("images/does-not-exist.gif"));
     }
 
 }