commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils ConvertUtilsTestCase.java
Date Sat, 15 Jun 2002 20:39:44 GMT
craigmcc    2002/06/15 13:39:44

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        ConvertUtils.java
               beanutils/src/test/org/apache/commons/beanutils
                        ConvertUtilsTestCase.java
  Log:
  Make convert(Object) return null if it is passed a zero-length array,
  instead of throwing IndexOutOfBoundsException.
  
  Add test cases for Object->String conversions.
  
  Revision  Changes    Path
  1.8       +7 -4      jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConvertUtils.java
  
  Index: ConvertUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/ConvertUtils.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ConvertUtils.java	18 Mar 2002 16:32:42 -0000	1.7
  +++ ConvertUtils.java	15 Jun 2002 20:39:44 -0000	1.8
  @@ -322,6 +322,9 @@
           if (value == null) {
               return ((String) null);
           } else if (value.getClass().isArray()) {
  +            if (Array.getLength(value) < 1) {
  +                return (null);
  +            }
               value = Array.get(value, 0);
               if (value == null)
                   return ((String) null);
  
  
  
  1.2       +64 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/ConvertUtilsTestCase.java
  
  Index: ConvertUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/ConvertUtilsTestCase.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ConvertUtilsTestCase.java	18 Mar 2002 16:32:43 -0000	1.1
  +++ ConvertUtilsTestCase.java	15 Jun 2002 20:39:44 -0000	1.2
  @@ -203,6 +203,66 @@
   
   
       /**
  +     * Test conversion of object to string for arrays.
  +     */
  +    public void testObjectToStringArray() {
  +
  +        int intArray0[] = new int[0];
  +        int intArray1[] = { 123 };
  +        int intArray2[] = { 123, 456 };
  +        String stringArray0[] = new String[0];
  +        String stringArray1[] = { "abc" };
  +        String stringArray2[] = { "abc", "def" };
  +
  +        assertEquals("intArray0", null,
  +                     ConvertUtils.convert(intArray0));
  +        assertEquals("intArray1", "123",
  +                     ConvertUtils.convert(intArray1));
  +        assertEquals("intArray2", "123",
  +                     ConvertUtils.convert(intArray2));
  +
  +        assertEquals("stringArray0", null,
  +                     ConvertUtils.convert(stringArray0));
  +        assertEquals("stringArray1", "abc",
  +                     ConvertUtils.convert(stringArray1));
  +        assertEquals("stringArray2", "abc",
  +                     ConvertUtils.convert(stringArray2));
  +
  +    }
  +
  +
  +    /**
  +     * Test conversion of object to string for scalars.
  +     */
  +    public void testObjectToStringScalar() {
  +
  +        assertEquals("Boolean->String", "false",
  +                     ConvertUtils.convert(Boolean.FALSE));
  +        assertEquals("Boolean->String", "true",
  +                     ConvertUtils.convert(Boolean.TRUE));
  +        assertEquals("Byte->String", "123",
  +                     ConvertUtils.convert(new Byte((byte) 123)));
  +        assertEquals("Character->String", "a",
  +                     ConvertUtils.convert(new Character('a')));
  +        assertEquals("Double->String", "123.0",
  +                     ConvertUtils.convert(new Double((double) 123.0)));
  +        assertEquals("Float->String", "123.0",
  +                     ConvertUtils.convert(new Float((float) 123.0)));
  +        assertEquals("Integer->String", "123",
  +                     ConvertUtils.convert(new Integer((int) 123)));
  +        assertEquals("Long->String", "123",
  +                     ConvertUtils.convert(new Long((long) 123)));
  +        assertEquals("Short->String", "123",
  +                     ConvertUtils.convert(new Short((short) 123)));
  +        assertEquals("String->String", "abc",
  +                     ConvertUtils.convert("abc"));
  +        assertEquals("String->String null", null,
  +                     ConvertUtils.convert(null));
  +
  +    }
  +
  +
  +    /**
        * Positive array conversion tests.
        */
       public void testPositiveArray() {
  
  
  

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


Mime
View raw message