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 TestBean.java
Date Sat, 01 Feb 2003 07:45:29 GMT
craigmcc    2003/01/31 23:45:29

  Modified:    beanutils/src/java/org/apache/commons/beanutils/converters
                        ByteConverter.java
               beanutils/src/test/org/apache/commons/beanutils
                        BeanUtilsTestCase.java DynaBeanUtilsTestCase.java
                        TestBean.java
  Log:
  Add tests for narrowing and widening conversions (such as int->long and
  long->int) on BeanUtils.setProperty().
  
  There appears to be a problem on the double->integraltype and float->integraltype
  conversions; those tests are current commented out until investigation is
  completed, but there is probably an underlying bug in the 1.6 version of
  commons-beanutils.
  
  Revision  Changes    Path
  1.6       +6 -4      jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/ByteConverter.java
  
  Index: ByteConverter.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/java/org/apache/commons/beanutils/converters/ByteConverter.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ByteConverter.java	15 Jan 2003 21:59:40 -0000	1.5
  +++ ByteConverter.java	1 Feb 2003 07:45:29 -0000	1.6
  @@ -148,6 +148,8 @@
               }
           }
   
  +        // System.err.println("VALUE=" + value + ", TYPE=" + value.getClass().getName());
  +
           if (value instanceof Byte) {
               return (value);
           } else if (value instanceof Number) {
  
  
  
  1.18      +160 -8    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.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- BeanUtilsTestCase.java	3 Jan 2003 20:32:35 -0000	1.17
  +++ BeanUtilsTestCase.java	1 Feb 2003 07:45:29 -0000	1.18
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -116,12 +116,13 @@
       protected String describes[] =
       { "booleanProperty",
         "booleanSecond",
  +      "byteProperty",
         "doubleProperty",
         "dupProperty",
         "floatProperty",
         "intArray",
         //      "intIndexed",
  -      "intProperty",
  +      "longProperty",
         "listIndexed",
         "longProperty",
         //      "mappedProperty",
  @@ -191,6 +192,7 @@
               fail("newInstance(): " + e);
           }
           orig.set("booleanProperty", Boolean.FALSE);
  +        orig.set("byteProperty", new Byte((byte) 111));
           orig.set("doubleProperty", new Double(333.33));
           orig.set("dupProperty",
                    new String[] { "New 0", "New 1", "New 2" });
  @@ -212,6 +214,9 @@
           assertEquals("Copied boolean property",
                        false,
                        bean.getBooleanProperty());
  +        assertEquals("Copied byte property",
  +                     (byte) 111,
  +                     bean.getByteProperty());
           assertEquals("Copied double property",
                        333.33,
                        bean.getDoubleProperty(),
  @@ -258,6 +263,7 @@
   
           Map map = new HashMap();
           map.put("booleanProperty", "false");
  +        map.put("byteProperty", "111");
           map.put("doubleProperty", "333.0");
           map.put("dupProperty", new String[] { "New 0", "New 1", "New 2" });
           map.put("floatProperty", "222.0");
  @@ -276,11 +282,13 @@
           // Scalar properties
           assertEquals("booleanProperty", false,
                        bean.getBooleanProperty());
  +        assertEquals("byteProperty", (byte) 111,
  +                     bean.getByteProperty());
           assertEquals("doubleProperty", 333.0,
                        bean.getDoubleProperty(), 0.005);
           assertEquals("floatProperty", (float) 222.0,
                        bean.getFloatProperty(), (float) 0.005);
  -        assertEquals("intProperty", 111,
  +        assertEquals("longProperty", 111,
                        bean.getIntProperty());
           assertEquals("longProperty", (long) 444,
                        bean.getLongProperty());
  @@ -288,7 +296,7 @@
                        bean.getShortProperty());
           assertEquals("stringProperty", "New String Property",
                        bean.getStringProperty());
  -                     
  +
           // Indexed Properties
           String dupProperty[] = bean.getDupProperty();
           assertNotNull("dupProperty present", dupProperty);
  @@ -314,6 +322,7 @@
           // Set up an origin bean with customized properties
           TestBean orig = new TestBean();
           orig.setBooleanProperty(false);
  +        orig.setByteProperty((byte) 111);
           orig.setDoubleProperty(333.33);
           orig.setDupProperty(new String[] { "New 0", "New 1", "New 2" });
           orig.setIntArray(new int[] { 100, 200, 300 });
  @@ -334,6 +343,9 @@
           assertEquals("Copied boolean property",
                        false,
                        bean.getBooleanProperty());
  +        assertEquals("Copied byte property",
  +                     (byte) 111,
  +                     bean.getByteProperty());
           assertEquals("Copied double property",
                        333.33,
                        bean.getDoubleProperty(),
  @@ -397,6 +409,9 @@
           assertEquals("Value of 'booleanProperty'",
                        "true",
                        (String) map.get("booleanProperty"));
  +        assertEquals("Value of 'byteProperty'",
  +                     "121",
  +                     (String) map.get("byteProperty"));
           assertEquals("Value of 'doubleProperty'",
                        "321.0",
                        (String) map.get("doubleProperty"));
  @@ -739,6 +754,7 @@
               HashMap map = new HashMap();
               map.put("booleanProperty", "false");
               // booleanSecond is left at true
  +            map.put("byteProperty", "111");
               map.put("doubleProperty", "432.0");
               // floatProperty is left at 123.0
               map.put("intProperty", "543");
  @@ -752,6 +768,8 @@
   
               assertTrue("booleanProperty is false", !bean.getBooleanProperty());
               assertTrue("booleanSecond is true", bean.isBooleanSecond());
  +            assertEquals("byteProperty is 111",
  +                         (byte) 111, bean.getByteProperty());
               assertEquals("doubleProperty is 432.0",
                            (double) 432.0, bean.getDoubleProperty(),
                            (double) 0.005);
  @@ -833,6 +851,140 @@
           assertEquals(1,bean.getIntProperty());
           BeanUtils.setProperty(bean,"stringProperty", new Integer(1));
           assertEquals(1, Integer.parseInt(bean.getStringProperty()));
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on byte.
  +     */
  +    public void testSetPropertyByte() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "byteProperty", new Byte((byte) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +/*
  +        BeanUtils.setProperty(bean, "byteProperty", new Double((double) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +        BeanUtils.setProperty(bean, "byteProperty", new Float((float) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +*/
  +        BeanUtils.setProperty(bean, "byteProperty", new Integer((int) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +        BeanUtils.setProperty(bean, "byteProperty", new Long((long) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +        BeanUtils.setProperty(bean, "byteProperty", new Short((short) 123));
  +        assertEquals((byte) 123, bean.getByteProperty());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on double.
  +     */
  +    public void testSetPropertyDouble() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "doubleProperty", new Byte((byte) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Double((double) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Float((float) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Integer((int) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Long((long) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Short((short) 123));
  +        assertEquals((double) 123, bean.getDoubleProperty(), 0.005);
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on float.
  +     */
  +    public void testSetPropertyFloat() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "floatProperty", new Byte((byte) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Double((double) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Float((float) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Integer((int) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Long((long) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Short((short) 123));
  +        assertEquals((float) 123, bean.getFloatProperty(), 0.005);
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on int.
  +     */
  +    public void testSetPropertyInteger() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +/*
  +        BeanUtils.setProperty(bean, "longProperty", new Double((double) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +        BeanUtils.setProperty(bean, "longProperty", new Float((float) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +*/
  +        BeanUtils.setProperty(bean, "longProperty", new Integer((int) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +        BeanUtils.setProperty(bean, "longProperty", new Long((long) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +        BeanUtils.setProperty(bean, "longProperty", new Short((short) 123));
  +        assertEquals((int) 123, bean.getIntProperty());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on long.
  +     */
  +    public void testSetPropertyLong() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +/*
  +        BeanUtils.setProperty(bean, "longProperty", new Double((double) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +        BeanUtils.setProperty(bean, "longProperty", new Float((float) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +*/
  +        BeanUtils.setProperty(bean, "longProperty", new Integer((int) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +        BeanUtils.setProperty(bean, "longProperty", new Long((long) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +        BeanUtils.setProperty(bean, "longProperty", new Short((short) 123));
  +        assertEquals((long) 123, bean.getLongProperty());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on short.
  +     */
  +    public void testSetPropertyShort() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "shortProperty", new Byte((byte) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +/*
  +        BeanUtils.setProperty(bean, "shortProperty", new Double((double) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +        BeanUtils.setProperty(bean, "shortProperty", new Float((float) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +*/
  +        BeanUtils.setProperty(bean, "shortProperty", new Integer((int) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +        BeanUtils.setProperty(bean, "shortProperty", new Long((long) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
  +        BeanUtils.setProperty(bean, "shortProperty", new Short((short) 123));
  +        assertEquals((short) 123, bean.getShortProperty());
   
       }
   
  
  
  
  1.15      +157 -6    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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- DynaBeanUtilsTestCase.java	3 Jan 2003 20:32:35 -0000	1.14
  +++ DynaBeanUtilsTestCase.java	1 Feb 2003 07:45:29 -0000	1.15
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -104,6 +104,7 @@
       protected String describes[] =
       { "booleanProperty",
         "booleanSecond",
  +      "byteProperty",
         "doubleProperty",
         "dupProperty",
         "floatProperty",
  @@ -154,6 +155,7 @@
           // Initialize the DynaBean's property values (like TestBean)
           bean.set("booleanProperty", new Boolean(true));
           bean.set("booleanSecond", new Boolean(true));
  +        bean.set("byteProperty", new Byte((byte) 121));
           bean.set("doubleProperty", new Double(321.0));
           bean.set("floatProperty", new Float((float) 123.0));
           String dupProperty[] = { "Dup 0", "Dup 1", "Dup 2", "Dup 3", "Dup 4"};
  @@ -233,6 +235,7 @@
               fail("newInstance(): " + e);
           }
           orig.set("booleanProperty", Boolean.FALSE);
  +        orig.set("byteProperty", new Byte((byte)111));
           orig.set("doubleProperty", new Double(333.33));
           orig.set("dupProperty", new String[] { "New 0", "New 1", "New 2" });
           orig.set("intArray", new int[] { 100, 200, 300 });
  @@ -253,6 +256,9 @@
           assertEquals("Copied boolean property",
                        false,
                        ((Boolean) bean.get("booleanProperty")).booleanValue());
  +        assertEquals("Copied byte property",
  +                     (byte) 111,
  +                     ((Byte) bean.get("byteProperty")).byteValue());
           assertEquals("Copied double property",
                        333.33,
                        ((Double) bean.get("doubleProperty")).doubleValue(),
  @@ -299,6 +305,7 @@
   
           Map map = new HashMap();
           map.put("booleanProperty", "false");
  +        map.put("byteProperty", "111");
           map.put("doubleProperty", "333.0");
           map.put("dupProperty", new String[] { "New 0", "New 1", "New 2" });
           map.put("floatProperty", "222.0");
  @@ -317,6 +324,8 @@
           // Scalar properties
           assertEquals("booleanProperty", false,
                        ((Boolean) bean.get("booleanProperty")).booleanValue());
  +        assertEquals("byteProperty", (byte) 111,
  +                     ((Byte) bean.get("byteProperty")).byteValue());
           assertEquals("doubleProperty", 333.0,
                        ((Double) bean.get("doubleProperty")).doubleValue(),
                        0.005);
  @@ -331,7 +340,7 @@
                        ((Short) bean.get("shortProperty")).shortValue());
           assertEquals("stringProperty", "New String Property",
                        (String) bean.get("stringProperty"));
  -                     
  +
           // Indexed Properties
           String dupProperty[] = (String[]) bean.get("dupProperty");
           assertNotNull("dupProperty present", dupProperty);
  @@ -357,6 +366,7 @@
           // Set up an origin bean with customized properties
           TestBean orig = new TestBean();
           orig.setBooleanProperty(false);
  +        orig.setByteProperty((byte) 111);
           orig.setDoubleProperty(333.33);
           orig.setDupProperty(new String[] { "New 0", "New 1", "New 2" });
           orig.setIntArray(new int[] { 100, 200, 300 });
  @@ -377,6 +387,9 @@
           assertEquals("Copied boolean property",
                        false,
                        ((Boolean) bean.get("booleanProperty")).booleanValue());
  +        assertEquals("Copied byte property",
  +                     (byte) 111,
  +                     ((Byte) bean.get("byteProperty")).byteValue());
           assertEquals("Copied double property",
                        333.33,
                        ((Double) bean.get("doubleProperty")).doubleValue(),
  @@ -440,6 +453,9 @@
           assertEquals("Value of 'booleanProperty'",
                        Boolean.TRUE,
                        (Boolean) map.get("booleanProperty"));
  +        assertEquals("Value of 'byteProperty'",
  +                     new Byte((byte) 121),
  +                     (Byte) map.get("byteProperty"));
           assertEquals("Value of 'doubleProperty'",
                        new Double(321.0),
                        (Double) map.get("doubleProperty"));
  @@ -887,6 +903,140 @@
       }
   
   
  +    /**
  +     * Test narrowing and widening conversions on byte.
  +     */
  +    public void testSetPropertyByte() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "byteProperty", new Byte((byte) 123));
  +        assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
  +/*
  +        BeanUtils.setProperty(bean, "byteProperty", new Double((double) 123));
  +        assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
  +        BeanUtils.setProperty(bean, "byteProperty", new Float((float) 123));
  +        assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
  +*/
  +        BeanUtils.setProperty(bean, "byteProperty", new Integer((int) 123));
  +        assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
  +        BeanUtils.setProperty(bean, "byteProperty", new Long((long) 123));
  +        assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
  +        BeanUtils.setProperty(bean, "byteProperty", new Short((short) 123));
  +        assertEquals((byte) 123, ((Byte) bean.get("byteProperty")).byteValue());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on double.
  +     */
  +    public void testSetPropertyDouble() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "doubleProperty", new Byte((byte) 123));
  +        assertEquals((double) 123, ((Double) bean.get("doubleProperty")).doubleValue(),
0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Double((double) 123));
  +        assertEquals((double) 123, ((Double) bean.get("doubleProperty")).doubleValue(),
0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Float((float) 123));
  +        assertEquals((double) 123, ((Double) bean.get("doubleProperty")).doubleValue(),
0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Integer((int) 123));
  +        assertEquals((double) 123, ((Double) bean.get("doubleProperty")).doubleValue(),
0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Long((long) 123));
  +        assertEquals((double) 123, ((Double) bean.get("doubleProperty")).doubleValue(),
0.005);
  +        BeanUtils.setProperty(bean, "doubleProperty", new Short((short) 123));
  +        assertEquals((double) 123, ((Double) bean.get("doubleProperty")).doubleValue(),
0.005);
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on float.
  +     */
  +    public void testSetPropertyFloat() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "floatProperty", new Byte((byte) 123));
  +        assertEquals((float) 123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Double((double) 123));
  +        assertEquals((float) 123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Float((float) 123));
  +        assertEquals((float) 123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Integer((int) 123));
  +        assertEquals((float) 123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Long((long) 123));
  +        assertEquals((float) 123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
  +        BeanUtils.setProperty(bean, "floatProperty", new Short((short) 123));
  +        assertEquals((float) 123, ((Float) bean.get("floatProperty")).floatValue(), 0.005);
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on int.
  +     */
  +    public void testSetPropertyInteger() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
  +        assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
  +/*
  +        BeanUtils.setProperty(bean, "longProperty", new Double((double) 123));
  +        assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
  +        BeanUtils.setProperty(bean, "longProperty", new Float((float) 123));
  +        assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
  +*/
  +        BeanUtils.setProperty(bean, "longProperty", new Integer((int) 123));
  +        assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
  +        BeanUtils.setProperty(bean, "longProperty", new Long((long) 123));
  +        assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
  +        BeanUtils.setProperty(bean, "longProperty", new Short((short) 123));
  +        assertEquals((int) 123, ((Integer) bean.get("intProperty")).intValue());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on long.
  +     */
  +    public void testSetPropertyLong() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "longProperty", new Byte((byte) 123));
  +        assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
  +/*
  +        BeanUtils.setProperty(bean, "longProperty", new Double((double) 123));
  +        assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
  +        BeanUtils.setProperty(bean, "longProperty", new Float((float) 123));
  +        assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
  +*/
  +        BeanUtils.setProperty(bean, "longProperty", new Integer((int) 123));
  +        assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
  +        BeanUtils.setProperty(bean, "longProperty", new Long((long) 123));
  +        assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
  +        BeanUtils.setProperty(bean, "longProperty", new Short((short) 123));
  +        assertEquals((long) 123, ((Long) bean.get("longProperty")).longValue());
  +
  +    }
  +
  +
  +    /**
  +     * Test narrowing and widening conversions on short.
  +     */
  +    public void testSetPropertyShort() throws Exception {
  +
  +        BeanUtils.setProperty(bean, "shortProperty", new Byte((byte) 123));
  +        assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
  +/*
  +        BeanUtils.setProperty(bean, "shortProperty", new Double((double) 123));
  +        assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
  +        BeanUtils.setProperty(bean, "shortProperty", new Float((float) 123));
  +        assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
  +*/
  +        BeanUtils.setProperty(bean, "shortProperty", new Integer((int) 123));
  +        assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
  +        BeanUtils.setProperty(bean, "shortProperty", new Long((long) 123));
  +        assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
  +        BeanUtils.setProperty(bean, "shortProperty", new Short((short) 123));
  +        assertEquals((short) 123, ((Short) bean.get("shortProperty")).shortValue());
  +
  +    }
  +
  +
       // ------------------------------------------------------ Protected Methods
   
   
  @@ -904,6 +1054,7 @@
                           new DynaProperty[]{
                               new DynaProperty("booleanProperty", Boolean.TYPE),
                               new DynaProperty("booleanSecond", Boolean.TYPE),
  +                            new DynaProperty("byteProperty", Byte.TYPE),
                               new DynaProperty("doubleProperty", Double.TYPE),
                               new DynaProperty("dupProperty", stringArray.getClass()),
                               new DynaProperty("floatProperty", Float.TYPE),
  
  
  
  1.15      +30 -16    jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java
  
  Index: TestBean.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/beanutils/src/test/org/apache/commons/beanutils/TestBean.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- TestBean.java	26 Nov 2002 23:25:57 -0000	1.14
  +++ TestBean.java	1 Feb 2003 07:45:29 -0000	1.15
  @@ -7,7 +7,7 @@
    *
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 1999-2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -83,11 +83,11 @@
   
       public TestBean() {
       }
  -    
  +
       public TestBean(String stringProperty) {
           setStringProperty(stringProperty);
       }
  -    
  +
       public TestBean(float floatProperty) {
           setFloatProperty(floatProperty);
       }
  @@ -95,11 +95,11 @@
       public TestBean(boolean booleanProperty) {
           setBooleanProperty(booleanProperty);
       }
  -    
  +
       public TestBean(Boolean booleanSecond) {
           setBooleanSecond(booleanSecond.booleanValue());
       }
  -    
  +
       public TestBean(float floatProperty, String stringProperty) {
           setFloatProperty(floatProperty);
           setStringProperty(stringProperty);
  @@ -118,7 +118,7 @@
       public TestBean(Integer intProperty) {
           setIntProperty(intProperty.intValue());
       }
  -    
  +
       TestBean(int intProperty) {
           setIntProperty(intProperty);
       }
  @@ -128,7 +128,7 @@
           setBooleanSecond(booleanSecond);
           setStringProperty(stringProperty);
       }
  -    
  +
       // ------------------------------------------------------------- Properties
   
   
  @@ -161,6 +161,20 @@
   
   
       /**
  +     * A byte property.
  +     */
  +    private byte byteProperty = (byte) 121;
  +
  +    public byte getByteProperty() {
  +        return (this.byteProperty);
  +    }
  +
  +    public void setByteProperty(byte byteProperty) {
  +        this.byteProperty = byteProperty;
  +    }
  +
  +
  +    /**
        * A double property.
        */
       private double doubleProperty = 321.0;
  @@ -400,15 +414,15 @@
       /*
        * Another nested reference to a bean containing mapp properties
        */
  -    class MappedTestBean { 
  +    class MappedTestBean {
           public void setValue(String key,String val) { }
           public String getValue(String key) { return "Mapped Value"; }
       }
  -    
  +
       private MappedTestBean mappedNested = null;
   
  -    public MappedTestBean getMappedNested() { 
  -        if (mappedNested == null) 
  +    public MappedTestBean getMappedNested() {
  +        if (mappedNested == null)
           {
               mappedNested = new MappedTestBean();
           }
  @@ -510,7 +524,7 @@
           this.writeOnlyProperty = writeOnlyProperty;
       }
   
  -    
  +
       // ------------------------------------------------------- Static Variables
   
   
  
  
  

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