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:39 UTC

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

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 76a4f988 JUnit5 assertThrows IBANValidatorTest
     new 8ba14f10 Merge pull request #94 from nhojpatrick/junit5-assertThrows-IBANValidatorTest
76a4f988 is described below

commit 76a4f9882a21e2534f2316759c4b0f514e3e824c
Author: John Patrick <14...@users.noreply.github.com>
AuthorDate: Thu Oct 15 13:14:53 2020 +0100

    JUnit5 assertThrows IBANValidatorTest
---
 .../validator/routines/IBANValidatorTest.java      | 35 +++++++++++++++-------
 1 file changed, 25 insertions(+), 10 deletions(-)

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 0a7b5e8d..a416ee96 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,13 @@
  */
 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.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -35,6 +39,7 @@ import org.apache.commons.csv.CSVRecord;
 import org.apache.commons.validator.routines.IBANValidator.Validator;
 import org.apache.commons.validator.routines.checkdigit.IBANCheckDigit;
 import org.junit.Test;
+import org.junit.function.ThrowingRunnable;
 
 /**
  * IBANValidator Test Case.
@@ -184,32 +189,42 @@ public class IBANValidatorTest {
         assertNull("gb", VALIDATOR.getValidator("gb"));
     }
 
-    @Test(expected=IllegalStateException.class)
+    @Test
     public void testSetDefaultValidator1() {
-        assertNotNull(VALIDATOR.setValidator("GB", 15, "GB"));
+        final IllegalStateException thrown = assertThrows(IllegalStateException.class, () ->
+                VALIDATOR.setValidator("GB", 15, "GB"));
+        assertThat(thrown.getMessage(), is(equalTo("The singleton validator cannot be modified")));
     }
 
-    @Test(expected=IllegalStateException.class)
+    @Test
     public void testSetDefaultValidator2() {
-        assertNotNull(VALIDATOR.setValidator("GB", -1, "GB"));
+        final IllegalStateException thrown = assertThrows(IllegalStateException.class, () ->
+                VALIDATOR.setValidator("GB", -1, "GB"));
+        assertThat(thrown.getMessage(), is(equalTo("The singleton validator cannot be modified")));
     }
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test
     public void testSetValidatorLC() {
         final IBANValidator validator = new IBANValidator();
-        assertNotNull(validator.setValidator("gb", 15, "GB"));
+        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")));
     }
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test
     public void testSetValidatorLen7() {
         final IBANValidator validator = new IBANValidator();
-        assertNotNull(validator.setValidator("GB", 7, "GB"));
+        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")));
     }
 
-    @Test(expected=IllegalArgumentException.class)
+    @Test
     public void testSetValidatorLen35() {
         final IBANValidator validator = new IBANValidator();
-        assertNotNull(validator.setValidator("GB", 35, "GB")); // valid params, but immutable validator
+        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")));
     }
 
     @Test