You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by pa...@apache.org on 2017/10/01 12:33:46 UTC
[1/3] [lang] CharUtilsTest#testIsAscii_char loop
Repository: commons-lang
Updated Branches:
refs/heads/master 7076b7408 -> d65b9d2be
CharUtilsTest#testIsAscii_char loop
The loop currently loops only up to 128, thus testing just positive
return values of CharUtils#isAscii(char). This patch increase the loop
to go over all the possible values of an unsigned byte, thus testing
also negative return values.
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/ae862ae1
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/ae862ae1
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/ae862ae1
Branch: refs/heads/master
Commit: ae862ae116f2056421ab8d6e997e7b64a95828a5
Parents: c755415
Author: Allon Mureinik <am...@redhat.com>
Authored: Sat Sep 30 15:27:42 2017 +0300
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sun Oct 1 14:33:16 2017 +0200
----------------------------------------------------------------------
src/test/java/org/apache/commons/lang3/CharUtilsTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/ae862ae1/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 35f7f02..71975d3 100644
--- a/src/test/java/org/apache/commons/lang3/CharUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharUtilsTest.java
@@ -219,7 +219,7 @@ public class CharUtilsTest {
assertTrue(CharUtils.isAscii('\n'));
assertFalse(CharUtils.isAscii(CHAR_COPY));
- for (int i = 0; i < 128; i++) {
+ for (int i = 0; i < 255; i++) {
assertEquals(i < 128, CharUtils.isAscii((char) i));
}
}
[3/3] [lang] Improve tests for CharUtils illegal usages (closes #293)
Posted by pa...@apache.org.
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 <am...@redhat.com>
Authored: Sat Sep 30 15:32:54 2017 +0300
Committer: pascalschumacher <pa...@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) {}
}
[2/3] [lang] Clean up if in CharUtilsTest#testIsAscii_char
Posted by pa...@apache.org.
Clean up if in CharUtilsTest#testIsAscii_char
The if statement calls assertTrue on the if branch and assertFalse on
the else branch on the same expression. This can easily be simplified
to assertEquals with a boolean expression to make the code clean and
easier to read.
Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/c7554151
Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/c7554151
Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/c7554151
Branch: refs/heads/master
Commit: c7554151d3f695718a5bd431e22c7f4c39a0b261
Parents: 7076b74
Author: Allon Mureinik <am...@redhat.com>
Authored: Sat Sep 30 15:25:34 2017 +0300
Committer: pascalschumacher <pa...@gmx.net>
Committed: Sun Oct 1 14:33:16 2017 +0200
----------------------------------------------------------------------
src/test/java/org/apache/commons/lang3/CharUtilsTest.java | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/commons-lang/blob/c7554151/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 bd92c33..35f7f02 100644
--- a/src/test/java/org/apache/commons/lang3/CharUtilsTest.java
+++ b/src/test/java/org/apache/commons/lang3/CharUtilsTest.java
@@ -220,11 +220,7 @@ public class CharUtilsTest {
assertFalse(CharUtils.isAscii(CHAR_COPY));
for (int i = 0; i < 128; i++) {
- if (i < 128) {
- assertTrue(CharUtils.isAscii((char) i));
- } else {
- assertFalse(CharUtils.isAscii((char) i));
- }
+ assertEquals(i < 128, CharUtils.isAscii((char) i));
}
}