commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdon...@apache.org
Subject cvs commit: jakarta-commons/beanutils/src/test/org/apache/commons/beanutils BeanUtilsTestCase.java
Date Wed, 26 Mar 2003 19:51:46 GMT
rdonkin     2003/03/26 11:51:46

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        BeanUtilsBean.java
               beanutils/src/test/org/apache/commons/beanutils
                        BeanUtilsTestCase.java
  Log:
  Made BeanUtils.getArrayProperty conversions use ConvertUtils (rather than just toString).
This enhancement is bug #17663.
  
  Revision  Changes    Path
  1.4       +8 -6      jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtilsBean.java
  
  Index: BeanUtilsBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/BeanUtilsBean.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BeanUtilsBean.java	20 Mar 2003 20:12:24 -0000	1.3
  +++ BeanUtilsBean.java	26 Mar 2003 19:51:46 -0000	1.4
  @@ -547,7 +547,8 @@
                   if (item == null) {
                       values.add((String) null);
                   } else {
  -                    values.add(item.toString());
  +                    // convert to string using convert utils
  +                    values.add(getConvertUtils().convert(item));
                   }
               }
               return ((String[]) values.toArray(new String[values.size()]));
  @@ -559,7 +560,8 @@
                   if (item == null) {
                       results[i] = null;
                   } else {
  -                    results[i] = item.toString();
  +                    // convert to string using convert utils
  +                    results[i] = getConvertUtils().convert(item);
                   }
               }
               return (results);
  
  
  
  1.24      +31 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java
  
  Index: BeanUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/BeanUtilsTestCase.java,v
  retrieving revision 1.23
  retrieving revision 1.24
  diff -u -r1.23 -r1.24
  --- BeanUtilsTestCase.java	15 Mar 2003 11:38:11 -0000	1.23
  +++ BeanUtilsTestCase.java	26 Mar 2003 19:51:46 -0000	1.24
  @@ -1293,6 +1293,33 @@
           }
       }
   
  +    public void testArrayPropertyConversion() throws Exception {
  +        BeanUtilsBean beanUtils = new BeanUtilsBean(	
  +                                                    new ConvertUtilsBean(), 
  +                                                    new PropertyUtilsBean());
  +        beanUtils.getConvertUtils().register(
  +            new Converter () {
  +                public Object convert(Class type, Object value) {
  +                    return "Spam, spam, spam, spam!";
  +                }
  +            },
  +            String.class);
  +            
  +        TestBean bean = new TestBean();
  +        String [] results = beanUtils.getArrayProperty(bean, "intArray");
  +                
  +        int[] values = bean.getIntArray();
  +        assertEquals(
  +                    "Converted array size not equal to property array size.",
  +                    results.length,
  +                    values.length);
  +        for (int i=0, size=values.length ;  i<size; i++) {
  +            assertEquals(
  +                    "Value " + i + " incorrectly converted ", 
  +                    "Spam, spam, spam, spam!",
  +                    results[i]);
  +        }
  +    }
   
       // Ensure that the actual int[] matches the expected int[]
       protected void checkIntArray(int actual[], int expected[]) {
  
  
  

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


Mime
View raw message