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 BeanUtilsTestCase.java DynaBeanUtilsTestCase.java
Date Sat, 01 Feb 2003 08:14:33 GMT
craigmcc    2003/02/01 00:14:33

  Modified:    beanutils/src/test/org/apache/commons/beanutils
                        BeanUtilsTestCase.java DynaBeanUtilsTestCase.java
  Log:
  Add tests for BeanUtils.copyProperty() with type conversion.  In this case,
  double-->integraltype and float-->integraltype conversions work fine
  because no intermediate conversion to String is performed.  This method
  (copyProperty) is what should be used for general type conversion, so the
  restriction on BeanUtils.setProperty() is a non-issue and the version 1.6
  release of commons-beanutils is OK.
  
  Revision  Changes    Path
  1.19      +130 -5    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- BeanUtilsTestCase.java	1 Feb 2003 07:45:29 -0000	1.18
  +++ BeanUtilsTestCase.java	1 Feb 2003 08:14:33 -0000	1.19
  @@ -989,5 +989,130 @@
       }
   
   
  -}
  +    /**
  +     * Test narrowing and widening conversions on byte.
  +     */
  +    public void testCopyPropertyByte() throws Exception {
  +
  +        BeanUtils.copyProperty(bean, "byteProperty", new Byte((byte) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +        BeanUtils.copyProperty(bean, "byteProperty", new Double((double) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +        BeanUtils.copyProperty(bean, "byteProperty", new Float((float) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +        BeanUtils.copyProperty(bean, "byteProperty", new Integer((int) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +        BeanUtils.copyProperty(bean, "byteProperty", new Long((long) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +        BeanUtils.copyProperty(bean, "byteProperty", new Short((short) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on double.
  +     */
  +    public void testCopyPropertyDouble() throws Exception {
  +
  +        BeanUtils.copyProperty(bean, "doubleProperty", new Byte((byte) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "doubleProperty", new Double((double) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "doubleProperty", new Float((float) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "doubleProperty", new Integer((int) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "doubleProperty", new Long((long) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "doubleProperty", new Short((short) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on float.
  +     */
  +    public void testCopyPropertyFloat() throws Exception {
  +
  +        BeanUtils.copyProperty(bean, "floatProperty", new Byte((byte) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "floatProperty", new Double((double) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "floatProperty", new Float((float) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "floatProperty", new Integer((int) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "floatProperty", new Long((long) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.copyProperty(bean, "floatProperty", new Short((short) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on int.
  +     */
  +    public void testCopyPropertyInteger() throws Exception {
   
  +        BeanUtils.copyProperty(bean, "longProperty", new Byte((byte) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Double((double) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Float((float) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Integer((int) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Long((long) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Short((short) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on long.
  +     */
  +    public void testCopyPropertyLong() throws Exception {
  +
  +        BeanUtils.copyProperty(bean, "longProperty", new Byte((byte) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Double((double) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Float((float) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Integer((int) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Long((long) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +        BeanUtils.copyProperty(bean, "longProperty", new Short((short) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on short.
  +     */
  +    public void testCopyPropertyShort() throws Exception {
  +
  +        BeanUtils.copyProperty(bean, "shortProperty", new Byte((byte) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +        BeanUtils.copyProperty(bean, "shortProperty", new Double((double) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +        BeanUtils.copyProperty(bean, "shortProperty", new Float((float) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +        BeanUtils.copyProperty(bean, "shortProperty", new Integer((int) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +        BeanUtils.copyProperty(bean, "shortProperty", new Long((long) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +        BeanUtils.copyProperty(bean, "shortProperty", new Short((short) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +
  +    }
  +
  +
  +}
  
  
  
  1.16      +10 -10    jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java
  
  Index: DynaBeanUtilsTestCase.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/DynaBeanUtilsTestCase.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DynaBeanUtilsTestCase.java	1 Feb 2003 07:45:29 -0000	1.15
  +++ DynaBeanUtilsTestCase.java	1 Feb 2003 08:14:33 -0000	1.16
  @@ -906,7 +906,7 @@
       /**
        * Test narrowing and widening conversions on byte.
        */
  -    public void testSetPropertyByte() throws Exception {
  +    public void testCopyPropertyByte() throws Exception {
   
           BeanUtils.setProperty(bean, "byteProperty", new Byte((byte) 123));
           assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
  @@ -929,7 +929,7 @@
       /**
        * Test narrowing and widening conversions on double.
        */
  -    public void testSetPropertyDouble() throws Exception {
  +    public void testCopyPropertyDouble() throws Exception {
   
           BeanUtils.setProperty(bean, "doubleProperty", new Byte((byte) 123));
           assertEquals((double) 123, ((Double) bean.get("doubleProperty")).doubleValue(),
0.005);
  @@ -950,7 +950,7 @@
       /**
        * Test narrowing and widening conversions on float.
        */
  -    public void testSetPropertyFloat() throws Exception {
  +    public void testCopyPropertyFloat() throws Exception {
   
           BeanUtils.setProperty(bean, "floatProperty", new Byte((byte) 123));
           assertEquals((float) 123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
  @@ -971,7 +971,7 @@
       /**
        * Test narrowing and widening conversions on int.
        */
  -    public void testSetPropertyInteger() throws Exception {
  +    public void testCopyPropertyInteger() throws Exception {
   
           BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
           assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
  @@ -994,7 +994,7 @@
       /**
        * Test narrowing and widening conversions on long.
        */
  -    public void testSetPropertyLong() throws Exception {
  +    public void testCopyPropertyLong() throws Exception {
   
           BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
           assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
  @@ -1017,7 +1017,7 @@
       /**
        * Test narrowing and widening conversions on short.
        */
  -    public void testSetPropertyShort() throws Exception {
  +    public void testCopyPropertyShort() throws Exception {
   
           BeanUtils.setProperty(bean, "shortProperty", new Byte((byte) 123));
           assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
  
  
  

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