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 2022/11/21 11:47:16 UTC

[commons-validator] branch master updated: JUnit5 assertThrows UrlValidatorTest

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-validator.git


The following commit(s) were added to refs/heads/master by this push:
     new 0afac16c JUnit5 assertThrows UrlValidatorTest
     new e1d8c8bc Merge pull request #95 from nhojpatrick/junit5-assertThrows-UrlValidatorTest
0afac16c is described below

commit 0afac16c4675892ff2a8bb0ecc24e5a2cc2dea8d
Author: John Patrick <14...@users.noreply.github.com>
AuthorDate: Wed Oct 14 22:51:37 2020 +0100

    JUnit5 assertThrows UrlValidatorTest
---
 .../validator/routines/UrlValidatorTest.java       | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java b/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
index dca36a64..d1ccc5b3 100644
--- a/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
@@ -16,6 +16,9 @@
  */
 package org.apache.commons.validator.routines;
 
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsEqual.equalTo;
 import static org.junit.Assert.*;
 
 import java.net.URI;
@@ -26,6 +29,7 @@ import java.util.List;
 import org.apache.commons.validator.ResultPair;
 import org.junit.Before;
 import org.junit.Test;
+import org.junit.function.ThrowingRunnable;
 
 /**
  * Performs Validation Test for url validations.
@@ -359,21 +363,27 @@ public class UrlValidatorTest {
       assertTrue(urlValidator.isValid("http://[::FFFF:129.144.52.38]:80/index.html"));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testValidator473_1() { // reject null DomainValidator
-        new UrlValidator(new String[]{}, null, 0L, null);
+        final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () ->
+                new UrlValidator(new String[]{}, null, 0L, null));
+        assertThat(thrown.getMessage(), is(equalTo("DomainValidator must not be null")));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testValidator473_2() { // reject null DomainValidator with mismatched allowLocal
         final List<DomainValidator.Item> items = new ArrayList<>();
-        new UrlValidator(new String[]{}, null, 0L, DomainValidator.getInstance(true, items));
+        final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () ->
+                new UrlValidator(new String[]{}, null, 0L, DomainValidator.getInstance(true, items)));
+        assertThat(thrown.getMessage(), is(equalTo("DomainValidator disagrees with ALLOW_LOCAL_URLS setting")));
     }
 
-    @Test(expected = IllegalArgumentException.class)
+    @Test
     public void testValidator473_3() { // reject null DomainValidator with mismatched allowLocal
         final List<DomainValidator.Item> items = new ArrayList<>();
-        new UrlValidator(new String[]{}, null, UrlValidator.ALLOW_LOCAL_URLS, DomainValidator.getInstance(false, items));
+        final IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () ->
+                new UrlValidator(new String[]{}, null, UrlValidator.ALLOW_LOCAL_URLS, DomainValidator.getInstance(false, items)));
+        assertThat(thrown.getMessage(), is(equalTo("DomainValidator disagrees with ALLOW_LOCAL_URLS setting")));
     }
 
     static boolean incrementTestPartsIndex(final int[] testPartsIndex, final Object[] testParts) {