commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: svn commit: r983219 - /commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Date Sun, 08 Aug 2010 17:39:33 GMT
On 7 August 2010 13:04,  <jcarman@apache.org> wrote:
> Author: jcarman
> Date: Sat Aug  7 12:04:46 2010
> New Revision: 983219
>
> URL: http://svn.apache.org/viewvc?rev=983219&view=rev
> Log:
> Some code clean-up.  Removing unnecessary boxing, array creation for varargs, etc.
>
> Modified:
>    commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
>
> Modified: commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
> URL: http://svn.apache.org/viewvc/commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java?rev=983219&r1=983218&r2=983219&view=diff
> ==============================================================================
> --- commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
(original)
> +++ commons/proper/lang/trunk/src/test/java/org/apache/commons/lang3/StringUtilsTest.java
Sat Aug  7 12:04:46 2010

...

> @@ -1330,28 +1330,28 @@ public class StringUtilsTest extends Tes
>     }
>
>     public void testLengthString() {
> -        assertEquals(0, StringUtils.length(null));
> -        assertEquals(0, StringUtils.length(""));
> -        assertEquals(0, StringUtils.length(StringUtils.EMPTY));
> -        assertEquals(1, StringUtils.length("A"));
> -        assertEquals(1, StringUtils.length(" "));
> -        assertEquals(8, StringUtils.length("ABCDEFGH"));
> +        assertEquals(0, CharSequenceUtils.length(null));
> +        assertEquals(0, CharSequenceUtils.length(""));
> +        assertEquals(0, CharSequenceUtils.length(StringUtils.EMPTY));
> +        assertEquals(1, CharSequenceUtils.length("A"));
> +        assertEquals(1, CharSequenceUtils.length(" "));
> +        assertEquals(8, CharSequenceUtils.length("ABCDEFGH"));
>     }

StringUtils.length() is now deprecated, and is replaced by
CharSequenceUtils.length(), but surely the deprecated methods should
still be tested?
The deprecation warnings can be suppressed.

When the deprecated method is deleted, the tests can be dropped entirely.

If the corresponding CharSequenceUtils.length() tests don't exist,
then they should be added.

>
>     public void testLengthStringBuffer() {
> -        assertEquals(0, StringUtils.length(new StringBuffer("")));
> -        assertEquals(0, StringUtils.length(new StringBuffer(StringUtils.EMPTY)));
> -        assertEquals(1, StringUtils.length(new StringBuffer("A")));
> -        assertEquals(1, StringUtils.length(new StringBuffer(" ")));
> -        assertEquals(8, StringUtils.length(new StringBuffer("ABCDEFGH")));
> +        assertEquals(0, CharSequenceUtils.length(new StringBuffer("")));
> +        assertEquals(0, CharSequenceUtils.length(new StringBuffer(StringUtils.EMPTY)));
> +        assertEquals(1, CharSequenceUtils.length(new StringBuffer("A")));
> +        assertEquals(1, CharSequenceUtils.length(new StringBuffer(" ")));
> +        assertEquals(8, CharSequenceUtils.length(new StringBuffer("ABCDEFGH")));
>     }

As above

>
>     public void testLengthStringBuilder() {
> -        assertEquals(0, StringUtils.length(new StringBuilder("")));
> -        assertEquals(0, StringUtils.length(new StringBuilder(StringUtils.EMPTY)));
> -        assertEquals(1, StringUtils.length(new StringBuilder("A")));
> -        assertEquals(1, StringUtils.length(new StringBuilder(" ")));
> -        assertEquals(8, StringUtils.length(new StringBuilder("ABCDEFGH")));
> +        assertEquals(0, CharSequenceUtils.length(new StringBuilder("")));
> +        assertEquals(0, CharSequenceUtils.length(new StringBuilder(StringUtils.EMPTY)));
> +        assertEquals(1, CharSequenceUtils.length(new StringBuilder("A")));
> +        assertEquals(1, CharSequenceUtils.length(new StringBuilder(" ")));
> +        assertEquals(8, CharSequenceUtils.length(new StringBuilder("ABCDEFGH")));
>     }

As above

> @@ -1826,33 +1826,33 @@ public class StringUtilsTest extends Tes
>     }
>
>     public void testGetCommonPrefix_StringArray(){
> -        assertEquals("", StringUtils.getCommonPrefix(null));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {}));
> -        assertEquals("abc", StringUtils.getCommonPrefix(new String[] {"abc"}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {null, null}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {"", ""}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {"", null}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {"abc", null,
null}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {null, null, "abc"}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {"", "abc"}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {"abc", ""}));
> -        assertEquals("abc", StringUtils.getCommonPrefix(new String[] {"abc", "abc"}));
> -        assertEquals("a", StringUtils.getCommonPrefix(new String[] {"abc", "a"}));
> -        assertEquals("ab", StringUtils.getCommonPrefix(new String[] {"ab", "abxyz"}));
> -        assertEquals("ab", StringUtils.getCommonPrefix(new String[] {"abcde", "abxyz"}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {"abcde", "xyz"}));
> -        assertEquals("", StringUtils.getCommonPrefix(new String[] {"xyz", "abcde"}));
> -        assertEquals("i am a ", StringUtils.getCommonPrefix(new String[] {"i am
a machine", "i am a robot"}));
> +        assertEquals("", StringUtils.getCommonPrefix((String[])null));
> +        assertEquals("", StringUtils.getCommonPrefix());
> +        assertEquals("abc", StringUtils.getCommonPrefix("abc"));
> +        assertEquals("", StringUtils.getCommonPrefix(null, null));
> +        assertEquals("", StringUtils.getCommonPrefix("", ""));
> +        assertEquals("", StringUtils.getCommonPrefix("", null));
> +        assertEquals("", StringUtils.getCommonPrefix("abc", null, null));
> +        assertEquals("", StringUtils.getCommonPrefix(null, null, "abc"));
> +        assertEquals("", StringUtils.getCommonPrefix("", "abc"));
> +        assertEquals("", StringUtils.getCommonPrefix("abc", ""));
> +        assertEquals("abc", StringUtils.getCommonPrefix("abc", "abc"));
> +        assertEquals("a", StringUtils.getCommonPrefix("abc", "a"));
> +        assertEquals("ab", StringUtils.getCommonPrefix("ab", "abxyz"));
> +        assertEquals("ab", StringUtils.getCommonPrefix("abcde", "abxyz"));
> +        assertEquals("", StringUtils.getCommonPrefix("abcde", "xyz"));
> +        assertEquals("", StringUtils.getCommonPrefix("xyz", "abcde"));
> +        assertEquals("i am a ", StringUtils.getCommonPrefix("i am a machine", "i
am a robot"));
>     }
>
>     public void testStartsWithAny() {
> -        assertFalse(StringUtils.startsWithAny(null, null));
> -        assertFalse(StringUtils.startsWithAny(null, new String[] {"abc"}));
> -        assertFalse(StringUtils.startsWithAny("abcxyz", null));
> -        assertFalse(StringUtils.startsWithAny("abcxyz", new String[] {}));
> -        assertTrue(StringUtils.startsWithAny("abcxyz", new String[] {"abc"}));
> -        assertTrue(StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz",
"abc"}));
> -        assertFalse(StringUtils.startsWithAny("abcxyz", new String[] {null, "xyz",
"abcd"}));
> +        assertFalse(StringUtils.startsWithAny(null, (String[])null));
> +        assertFalse(StringUtils.startsWithAny(null, "abc"));
> +        assertFalse(StringUtils.startsWithAny("abcxyz", (String[])null));
> +        assertFalse(StringUtils.startsWithAny("abcxyz"));
> +        assertTrue(StringUtils.startsWithAny("abcxyz", "abc"));
> +        assertTrue(StringUtils.startsWithAny("abcxyz", null, "xyz", "abc"));
> +        assertFalse(StringUtils.startsWithAny("abcxyz", null, "xyz", "abcd"));

Most of the above changes seem wrong to me, as they change what is being tested.

By all means add tests for varargs, but surely the array tests need to
be kept as well?

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message