Repository: commons-lang Updated Branches: refs/heads/master 8acb1d2b4 -> 2b52dedd5
Add tests for missed branches in StringUtils (closes #135) Side effect: close pull requests which have been merged, but have not been closed due to missing commit comments (close #115, close #120, close #128, close #130). Project: http://git-wip-us.apache.org/repos/asf/commons-lang/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-lang/commit/2b52dedd Tree: http://git-wip-us.apache.org/repos/asf/commons-lang/tree/2b52dedd Diff: http://git-wip-us.apache.org/repos/asf/commons-lang/diff/2b52dedd Branch: refs/heads/master Commit: 2b52dedd56503bf89b28cfbad21f59e3dd4d1d32 Parents: 8acb1d2 Author: Casey Scarborough <[email protected]> Authored: Sun Apr 24 11:46:10 2016 -0400 Committer: pascalschumacher <[email protected]> Committed: Sun May 8 14:22:21 2016 +0200 ---------------------------------------------------------------------- .../apache/commons/lang3/StringUtilsTest.java | 34 ++++++++++++++++++-- 1 file changed, 31 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-lang/blob/2b52dedd/src/test/java/org/apache/commons/lang3/StringUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java index 654a144..1fa164e 100644 --- a/src/test/java/org/apache/commons/lang3/StringUtilsTest.java +++ b/src/test/java/org/apache/commons/lang3/StringUtilsTest.java @@ -360,6 +360,9 @@ public class StringUtilsTest { assertNull(StringUtils.join((char[]) null, ',')); assertEquals("1;2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR)); assertEquals("2", StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 1, 2)); + assertNull(StringUtils.join((char[]) null, SEPARATOR_CHAR, 0, 1)); + assertEquals(StringUtils.EMPTY, StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); + assertEquals(StringUtils.EMPTY, StringUtils.join(CHAR_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); } @Test @@ -367,6 +370,9 @@ public class StringUtilsTest { assertNull(StringUtils.join((byte[]) null, ',')); assertEquals("1;2", StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR)); assertEquals("2", StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 1, 2)); + assertNull(StringUtils.join((byte[]) null, SEPARATOR_CHAR, 0, 1)); + assertEquals(StringUtils.EMPTY, StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); + assertEquals(StringUtils.EMPTY, StringUtils.join(BYTE_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); } @Test @@ -374,6 +380,9 @@ public class StringUtilsTest { assertNull(StringUtils.join((int[]) null, ',')); assertEquals("1;2", StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR)); assertEquals("2", StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 1, 2)); + assertNull(StringUtils.join((int[]) null, SEPARATOR_CHAR, 0, 1)); + assertEquals(StringUtils.EMPTY, StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); + assertEquals(StringUtils.EMPTY, StringUtils.join(INT_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); } @Test @@ -381,6 +390,9 @@ public class StringUtilsTest { assertNull(StringUtils.join((long[]) null, ',')); assertEquals("1;2", StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR)); assertEquals("2", StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 1, 2)); + assertNull(StringUtils.join((long[]) null, SEPARATOR_CHAR, 0, 1)); + assertEquals(StringUtils.EMPTY, StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); + assertEquals(StringUtils.EMPTY, StringUtils.join(LONG_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); } @Test @@ -388,6 +400,9 @@ public class StringUtilsTest { assertNull(StringUtils.join((float[]) null, ',')); assertEquals("1.0;2.0", StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR)); assertEquals("2.0", StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 1, 2)); + assertNull(StringUtils.join((float[]) null, SEPARATOR_CHAR, 0, 1)); + assertEquals(StringUtils.EMPTY, StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); + assertEquals(StringUtils.EMPTY, StringUtils.join(FLOAT_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); } @Test @@ -395,6 +410,9 @@ public class StringUtilsTest { assertNull(StringUtils.join((double[]) null, ',')); assertEquals("1.0;2.0", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR)); assertEquals("2.0", StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 1, 2)); + assertNull(StringUtils.join((double[]) null, SEPARATOR_CHAR, 0, 1)); + assertEquals(StringUtils.EMPTY, StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); + assertEquals(StringUtils.EMPTY, StringUtils.join(DOUBLE_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); } @Test @@ -402,6 +420,9 @@ public class StringUtilsTest { assertNull(StringUtils.join((short[]) null, ',')); assertEquals("1;2", StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR)); assertEquals("2", StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 1, 2)); + assertNull(StringUtils.join((short[]) null, SEPARATOR_CHAR, 0, 1)); + assertEquals(StringUtils.EMPTY, StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 0, 0)); + assertEquals(StringUtils.EMPTY, StringUtils.join(SHORT_PRIM_LIST, SEPARATOR_CHAR, 1, 0)); } @Test @@ -1362,6 +1383,13 @@ public class StringUtilsTest { // Test null safety inside arrays - LANG-552 assertEquals(StringUtils.replaceEach("aba", new String[]{"a"}, new String[]{null}), "aba"); assertEquals(StringUtils.replaceEach("aba", new String[]{"a", "b"}, new String[]{"c", null}), "cbc"); + + try { + StringUtils.replaceEach("abba", new String[]{"a"}, new String[]{"b", "a"}); + fail("StringUtils.replaceEach(String, String[], String[]) expecting IllegalArgumentException"); + } catch (final IllegalArgumentException ex) { + // expected + } } /** @@ -2501,8 +2529,8 @@ public class StringUtilsTest { assertEquals("121", StringUtils.stripEnd("121.00", ".0")); } - // Methods on StringUtils that are immutable in spirit (i.e. calculate the length) - // should take a CharSequence parameter. Methods that are mutable in spirit (i.e. capitalize) + // Methods on StringUtils that are immutable in spirit (i.e. calculate the length) + // should take a CharSequence parameter. Methods that are mutable in spirit (i.e. capitalize) // should take a String or String[] parameter and return String or String[]. // This test enforces that this is done. @Test @@ -2521,7 +2549,7 @@ public class StringUtilsTest { String methodStr = m.toString(); if (m.getReturnType() == String.class || m.getReturnType() == String[].class) { // Assume this is mutable and ensure the first parameter is not CharSequence. - // It may be String or it may be something else (String[], Object, Object[]) so + // It may be String or it may be something else (String[], Object, Object[]) so // don't actively test for that. final Class<?>[] params = m.getParameterTypes(); if (params.length > 0 && (params[0] == CharSequence.class || params[0] == CharSequence[].class)) {
