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

commit f56343157f81f578ee117a408b1fbed2b79fd1a8
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Tue Oct 1 13:33:53 2024 -0400

    Make test more readable and maintainable, and less verbose
    
    - Use JUnit 5 APIs
    - Be consistent throughout tests
---
 .../validator/routines/DomainValidatorStartupTest.java    | 12 +++++-------
 .../commons/validator/routines/EmailValidatorTest.java    |  9 +++------
 .../commons/validator/routines/IBANValidatorTest.java     | 15 +++++++--------
 .../commons/validator/routines/UrlValidatorTest.java      |  9 +++------
 4 files changed, 18 insertions(+), 27 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/validator/routines/DomainValidatorStartupTest.java
 
b/src/test/java/org/apache/commons/validator/routines/DomainValidatorStartupTest.java
index d92c412e..16a93edd 100644
--- 
a/src/test/java/org/apache/commons/validator/routines/DomainValidatorStartupTest.java
+++ 
b/src/test/java/org/apache/commons/validator/routines/DomainValidatorStartupTest.java
@@ -16,9 +16,7 @@
  */
 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.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertThrows;
@@ -82,28 +80,28 @@ public class DomainValidatorStartupTest {
     public void testUpdateBaseArrayCC() {
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class,
                 () -> 
DomainValidator.updateTLDOverride(ArrayType.COUNTRY_CODE_RO, "com"));
-        assertThat(thrown.getMessage(), is(equalTo("Cannot update the table: 
COUNTRY_CODE_RO")));
+        assertEquals("Cannot update the table: COUNTRY_CODE_RO", 
thrown.getMessage());
     }
 
     @Test
     public void testUpdateBaseArrayGeneric() {
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class,
                 () -> DomainValidator.updateTLDOverride(ArrayType.GENERIC_RO, 
"com"));
-        assertThat(thrown.getMessage(), is(equalTo("Cannot update the table: 
GENERIC_RO")));
+        assertEquals("Cannot update the table: GENERIC_RO", 
thrown.getMessage());
     }
 
     @Test
     public void testUpdateBaseArrayInfra() {
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class,
                 () -> 
DomainValidator.updateTLDOverride(ArrayType.INFRASTRUCTURE_RO, "com"));
-        assertThat(thrown.getMessage(), is(equalTo("Cannot update the table: 
INFRASTRUCTURE_RO")));
+        assertEquals("Cannot update the table: INFRASTRUCTURE_RO", 
thrown.getMessage());
     }
 
     @Test
     public void testUpdateBaseArrayLocal() {
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class,
                 () -> DomainValidator.updateTLDOverride(ArrayType.LOCAL_RO, 
"com"));
-        assertThat(thrown.getMessage(), is(equalTo("Cannot update the table: 
LOCAL_RO")));
+        assertEquals("Cannot update the table: LOCAL_RO", thrown.getMessage());
     }
 
     @Test
diff --git 
a/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java 
b/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
index 7dc2ee6d..8bee311d 100644
--- 
a/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
+++ 
b/src/test/java/org/apache/commons/validator/routines/EmailValidatorTest.java
@@ -16,9 +16,6 @@
  */
 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.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -548,7 +545,7 @@ public class EmailValidatorTest {
     @Test
     public void testValidator473Part1() { // reject null DomainValidator
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class, () -> new EmailValidator(false, 
false, null));
-        assertThat(thrown.getMessage(), is(equalTo("DomainValidator cannot be 
null")));
+        assertEquals("DomainValidator cannot be null", thrown.getMessage());
     }
 
     @Test
@@ -556,7 +553,7 @@ public class EmailValidatorTest {
         final List<DomainValidator.Item> items = new ArrayList<>();
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class,
                 () -> new EmailValidator(false, false, 
DomainValidator.getInstance(true, items)));
-        assertThat(thrown.getMessage(), is(equalTo("DomainValidator must agree 
with allowLocal setting")));
+        assertEquals("DomainValidator must agree with allowLocal setting", 
thrown.getMessage());
     }
 
     @Test
@@ -564,7 +561,7 @@ public class EmailValidatorTest {
         final List<DomainValidator.Item> items = new ArrayList<>();
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class,
                 () -> new EmailValidator(true, false, 
DomainValidator.getInstance(false, items)));
-        assertThat(thrown.getMessage(), is(equalTo("DomainValidator must agree 
with allowLocal setting")));
+        assertEquals("DomainValidator must agree with allowLocal setting", 
thrown.getMessage());
     }
 
     @Test
diff --git 
a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java 
b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
index c2098355..79124cba 100644
--- a/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/IBANValidatorTest.java
@@ -16,9 +16,7 @@
  */
 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.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
 import static org.junit.jupiter.api.Assertions.assertNull;
@@ -359,20 +357,21 @@ public class IBANValidatorTest {
     @Test
     public void testSetDefaultValidator1() {
         final IllegalStateException thrown = 
assertThrows(IllegalStateException.class, () -> VALIDATOR.setValidator("GB", 
15, "GB"));
-        assertThat(thrown.getMessage(), is(equalTo("The singleton validator 
cannot be modified")));
+        assertEquals("The singleton validator cannot be modified", 
thrown.getMessage());
+
     }
 
     @Test
     public void testSetDefaultValidator2() {
         final IllegalStateException thrown = 
assertThrows(IllegalStateException.class, () -> VALIDATOR.setValidator("GB", 
-1, "GB"));
-        assertThat(thrown.getMessage(), is(equalTo("The singleton validator 
cannot be modified")));
+        assertEquals("The singleton validator cannot be modified", 
thrown.getMessage());
     }
 
     @Test
     public void testSetValidatorLC() {
         final IBANValidator validator = new IBANValidator();
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class, () -> validator.setValidator("gb", 
15, "GB"));
-        assertThat(thrown.getMessage(), is(equalTo("Invalid country Code; must 
be exactly 2 upper-case characters")));
+        assertEquals("Invalid country Code; must be exactly 2 upper-case 
characters", thrown.getMessage());
     }
 
     @Test
@@ -386,14 +385,14 @@ public class IBANValidatorTest {
     public void testSetValidatorLen35() {
         final IBANValidator validator = new IBANValidator();
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class, () -> validator.setValidator("GB", 
35, "GB"));
-        assertThat(thrown.getMessage(), is(equalTo("Invalid length parameter, 
must be in range 8 to 34 inclusive: 35")));
+        assertEquals("Invalid length parameter, must be in range 8 to 34 
inclusive: 35", thrown.getMessage());
     }
 
     @Test
     public void testSetValidatorLen7() {
         final IBANValidator validator = new IBANValidator();
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class, () -> validator.setValidator("GB", 
7, "GB"));
-        assertThat(thrown.getMessage(), is(equalTo("Invalid length parameter, 
must be in range 8 to 34 inclusive: 7")));
+        assertEquals("Invalid length parameter, must be in range 8 to 34 
inclusive: 7", thrown.getMessage());
     }
 
     @Test
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 98953311..b3f54329 100644
--- a/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
+++ b/src/test/java/org/apache/commons/validator/routines/UrlValidatorTest.java
@@ -16,9 +16,6 @@
  */
 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.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertFalse;
 import static org.junit.jupiter.api.Assertions.assertThrows;
@@ -615,7 +612,7 @@ public class UrlValidatorTest {
     @Test
     public void testValidator473Part1() { // reject null DomainValidator
         final IllegalArgumentException thrown = 
assertThrows(IllegalArgumentException.class, () -> new UrlValidator(new 
String[] {}, null, 0L, null));
-        assertThat(thrown.getMessage(), is(equalTo("DomainValidator must not 
be null")));
+        assertEquals("DomainValidator must not be null", thrown.getMessage());
     }
 
     @Test
@@ -623,7 +620,7 @@ public class UrlValidatorTest {
         final List<DomainValidator.Item> items = new ArrayList<>();
         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")));
+        assertEquals("DomainValidator disagrees with ALLOW_LOCAL_URLS 
setting", thrown.getMessage());
     }
 
     @Test
@@ -631,7 +628,7 @@ public class UrlValidatorTest {
         final List<DomainValidator.Item> items = new ArrayList<>();
         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")));
+        assertEquals("DomainValidator disagrees with ALLOW_LOCAL_URLS 
setting", thrown.getMessage());
     }
 
 }

Reply via email to