commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject [3/3] [lang] Improve tests for CharUtils illegal usages (closes #293)
Date Sun, 01 Oct 2017 12:33:48 GMT
Improve tests for CharUtils illegal usages (closes #293)

CharUtilsTest has several instances of the following pattern:

    try {
        CharUtils.someMethod("illegal input");
    } catch (final IllegalArgumentException ex) {}

This pattern is not very useful for testing, as the test would pass
whether an IllegalArgumentException is thrown or not. This patch
enhances the test by explicitly failing it if the exception is not
thrown:

    try {
        CharUtils.someMethod("illegal input");
        fail("An IllegalArgumentException should have been thrown");
    } catch (final IllegalArgumentException ex) {}


Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/d65b9d2b
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/d65b9d2b
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/d65b9d2b

Branch: refs/heads/master
Commit: d65b9d2bed09847ef28b9ceb30c9f8a96e0c12fe
Parents: ae862ae
Author: Allon Mureinik <amureini@redhat.com>
Authored: Sat Sep 30 15:32:54 2017 +0300
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Sun Oct 1 14:33:21 2017 +0200

----------------------------------------------------------------------
 src/test/java/org/apache/commons/lang3/CharUtilsTest.java | 7 +++++++
 1 file changed, 7 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-lang/blob/d65b9d2b/src/test/java/org/apache/commons/lang3/CharUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/lang3/CharUtilsTest.java b/src/test/java/org/apache/commons/lang3/CharUtilsTest.java
index 71975d3..50f2634 100644
--- a/src/test/java/org/apache/commons/lang3/CharUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharUtilsTest.java
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
@@ -84,6 +85,7 @@ public class CharUtilsTest {
         assertEquals('B', CharUtils.toChar(CHARACTER_B));
         try {
             CharUtils.toChar((Character) null);
+            fail("An IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException ex) {}
     }
 
@@ -100,9 +102,11 @@ public class CharUtilsTest {
         assertEquals('B', CharUtils.toChar("BA"));
         try {
             CharUtils.toChar((String) null);
+            fail("An IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException ex) {}
         try {
             CharUtils.toChar("");
+            fail("An IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException ex) {}
     }
 
@@ -128,6 +132,7 @@ public class CharUtilsTest {
         assertEquals(9, CharUtils.toIntValue('9'));
         try {
             CharUtils.toIntValue('a');
+            fail("An IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException ex) {}
     }
 
@@ -144,9 +149,11 @@ public class CharUtilsTest {
         assertEquals(3, CharUtils.toIntValue(new Character('3')));
         try {
             CharUtils.toIntValue(null);
+            fail("An IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException ex) {}
         try {
             CharUtils.toIntValue(CHARACTER_A);
+            fail("An IllegalArgumentException should have been thrown");
         } catch (final IllegalArgumentException ex) {}
     }
 


Mime
View raw message