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 PropertyUtilsTestCase.java
Date Sat, 15 Jun 2002 20:22:01 GMT
craigmcc    2002/06/15 13:22:01

  Modified:    beanutils/src/java/org/apache/commons/beanutils
                        PropertyUtils.java
               beanutils/src/test/org/apache/commons/beanutils
                        PropertyUtilsTestCase.java
  Log:
  Make PropertyUtils.getPropertyType() return the class of the underlying
  mapped property, analogous to the way it works on indexed properties.
  
  Add test case for getPropertyType() method.
  
  PR: Bugzilla #8810
  Submitted by:	Viral Tolat <viral.tolat at integral.com>
  
  Revision  Changes    Path
  1.25      +7 -4      jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/PropertyUtils.java
  
  Index: PropertyUtils.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/PropertyUtils.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- PropertyUtils.java	28 Apr 2002 01:16:48 -0000	1.24
  +++ PropertyUtils.java	15 Jun 2002 20:22:01 -0000	1.25
  @@ -1028,6 +1028,9 @@
           } else if (descriptor instanceof IndexedPropertyDescriptor) {
               return (((IndexedPropertyDescriptor) descriptor).
                       getIndexedPropertyType());
  +        } else if (descriptor instanceof MappedPropertyDescriptor) {
  +            return (((MappedPropertyDescriptor) descriptor).
  +                    getMappedPropertyType());
           } else {
               return (descriptor.getPropertyType());
           }
  
  
  
  1.16      +57 -4     jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java
  
  Index: PropertyUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/PropertyUtilsTestCase.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- PropertyUtilsTestCase.java	23 Jan 2002 22:52:26 -0000	1.15
  +++ PropertyUtilsTestCase.java	15 Jun 2002 20:22:01 -0000	1.16
  @@ -66,6 +66,7 @@
   import java.beans.PropertyDescriptor;
   import java.lang.reflect.InvocationTargetException;
   import java.lang.reflect.Method;
  +import java.util.List;
   
   import org.apache.commons.beanutils.priv.PrivateBeanFactory;
   import org.apache.commons.beanutils.priv.PrivateDirect;
  @@ -90,6 +91,7 @@
    * <li>getNestedProperty(Object,String)</li>
    * <li>getPropertyDescriptor(Object,String)</li>
    * <li>getPropertyDescriptors(Object)</li>
  + * <li>getPropertyType(Object,String)</li>
    * <li>getSimpleProperty(Object,String)</li>
    * <li>setIndexedProperty(Object,String,Object)</li>
    * <li>setIndexedProperty(Object,String,String,Object)</li>
  @@ -1234,6 +1236,57 @@
               fail("InvocationTargetException");
           } catch (NoSuchMethodException e) {
               ; // Correct result for this test
  +        }
  +
  +    }
  +
  +
  +    /**
  +     * Test getPropertyType() on all kinds of properties.
  +     */
  +    public void testGetPropertyType() {
  +
  +        Class clazz = null;
  +        int intArray[] = new int[0];
  +        String stringArray[] = new String[0];
  +
  +        try {
  +            clazz = PropertyUtils.getPropertyType(bean, "booleanProperty");
  +            assertEquals("booleanProperty type", Boolean.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "booleanSecond");
  +            assertEquals("booleanSecond type", Boolean.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "doubleProperty");
  +            assertEquals("doubleProperty type", Double.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "floatProperty");
  +            assertEquals("floatProperty type", Float.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "intArray");
  +            assertEquals("intArray type", intArray.getClass(), clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "intIndexed");
  +            assertEquals("intIndexed type", Integer.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "intProperty");
  +            assertEquals("intProperty type", Integer.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "listIndexed");
  +            assertEquals("listIndexed type", List.class, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "longProperty");
  +            assertEquals("longProperty type", Long.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "mappedProperty");
  +            assertEquals("mappedProperty type", String.class, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "mappedIntProperty");
  +            assertEquals("mappedIntProperty type", Integer.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "readOnlyProperty");
  +            assertEquals("readOnlyProperty type", String.class, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "shortProperty");
  +            assertEquals("shortProperty type", Short.TYPE, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "stringArray");
  +            assertEquals("stringArray type", stringArray.getClass(), clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "stringIndexed");
  +            assertEquals("stringIndexed type", String.class, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "stringProperty");
  +            assertEquals("stringProperty type", String.class, clazz);
  +            clazz = PropertyUtils.getPropertyType(bean, "writeOnlyProperty");
  +            assertEquals("writeOnlyProperty type", String.class, clazz);
  +        } catch (Exception e) {
  +            fail("Exception: " + e.getMessage());
           }
   
       }
  
  
  

--
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