⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dynabeanutilstestcase.java

📁 apache beanutils开源项目源码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        assertNotNull("dupProperty present", dupProperty);        assertEquals("dupProperty length", 3, dupProperty.length);        assertEquals("dupProperty[0]", "New 0", dupProperty[0]);        assertEquals("dupProperty[1]", "New 1", dupProperty[1]);        assertEquals("dupProperty[2]", "New 2", dupProperty[2]);        int intArray[] = (int[]) bean.get("intArray");        assertNotNull("intArray present", intArray);        assertEquals("intArray length", 3, intArray.length);        assertEquals("intArray[0]", 100, intArray[0]);        assertEquals("intArray[1]", 200, intArray[1]);        assertEquals("intArray[2]", 300, intArray[2]);        String stringArray[] = (String[]) bean.get("stringArray");        assertNotNull("stringArray present", stringArray);        assertEquals("stringArray length", 2, stringArray.length);        assertEquals("stringArray[0]", "New 0", stringArray[0]);        assertEquals("stringArray[1]", "New 1", stringArray[1]);    }    /**     * Test copyProperties() when the origin is a a <code>Map</code>.     */    public void testCopyPropertiesMap() {        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");        map.put("intArray", new String[] { "0", "100", "200" });        map.put("intProperty", "111");        map.put("longProperty", "444");        map.put("shortProperty", "555");        map.put("stringProperty", "New String Property");        try {            BeanUtils.copyProperties(bean, map);        } catch (Throwable t) {            fail("Threw " + t.toString());        }        // 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);        assertEquals("floatProperty", (float) 222.0,                     ((Float) bean.get("floatProperty")).floatValue(),                     (float) 0.005);        assertEquals("intProperty", 111,                     ((Integer) bean.get("intProperty")).intValue());        assertEquals("longProperty", (long) 444,                     ((Long) bean.get("longProperty")).longValue());        assertEquals("shortProperty", (short) 555,                     ((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);        assertEquals("dupProperty length", 3, dupProperty.length);        assertEquals("dupProperty[0]", "New 0", dupProperty[0]);        assertEquals("dupProperty[1]", "New 1", dupProperty[1]);        assertEquals("dupProperty[2]", "New 2", dupProperty[2]);        int intArray[] = (int[]) bean.get("intArray");        assertNotNull("intArray present", intArray);        assertEquals("intArray length", 3, intArray.length);        assertEquals("intArray[0]", 0, intArray[0]);        assertEquals("intArray[1]", 100, intArray[1]);        assertEquals("intArray[2]", 200, intArray[2]);    }    /**     * Test the copyProperties() method from a standard JavaBean.     */    public void testCopyPropertiesStandard() {        // 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 });        orig.setIntProperty(333);        orig.setLongProperty(3333);        orig.setShortProperty((short) 33);        orig.setStringArray(new String[] { "New 0", "New 1" });        orig.setStringProperty("Custom string");        // Copy the origin bean to our destination test bean        try {            BeanUtils.copyProperties(bean, orig);        } catch (Exception e) {            fail("Threw exception: " + e);        }        // Validate the results for scalar properties        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(),                     0.005);        assertEquals("Copied int property",                     333,                     ((Integer) bean.get("intProperty")).intValue());        assertEquals("Copied long property",                     (long) 3333,                     ((Long) bean.get("longProperty")).longValue());        assertEquals("Copied short property",                     (short) 33,                     ((Short) bean.get("shortProperty")).shortValue());        assertEquals("Copied string property",                     "Custom string",                     (String) bean.get("stringProperty"));        // Validate the results for array properties        String dupProperty[] = (String[]) bean.get("dupProperty");        assertNotNull("dupProperty present", dupProperty);        assertEquals("dupProperty length", 3, dupProperty.length);        assertEquals("dupProperty[0]", "New 0", dupProperty[0]);        assertEquals("dupProperty[1]", "New 1", dupProperty[1]);        assertEquals("dupProperty[2]", "New 2", dupProperty[2]);        int intArray[] = (int[]) bean.get("intArray");        assertNotNull("intArray present", intArray);        assertEquals("intArray length", 3, intArray.length);        assertEquals("intArray[0]", 100, intArray[0]);        assertEquals("intArray[1]", 200, intArray[1]);        assertEquals("intArray[2]", 300, intArray[2]);        String stringArray[] = (String[]) bean.get("stringArray");        assertNotNull("stringArray present", stringArray);        assertEquals("stringArray length", 2, stringArray.length);        assertEquals("stringArray[0]", "New 0", stringArray[0]);        assertEquals("stringArray[1]", "New 1", stringArray[1]);    }    /**     * Test the describe() method.     */    public void testDescribe() {        Map map = null;        try {            map = PropertyUtils.describe(bean);        } catch (Exception e) {            fail("Threw exception " + e);        }        // Verify existence of all the properties that should be present        for (int i = 0; i < describes.length; i++) {            assertTrue("Property '" + describes[i] + "' is present",                       map.containsKey(describes[i]));        }        assertTrue("Property 'writeOnlyProperty' is not present",                   !map.containsKey("writeOnlyProperty"));        // Verify the values of scalar properties        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"));        assertEquals("Value of 'floatProperty'",                     new Float((float) 123.0),                     (Float) map.get("floatProperty"));        assertEquals("Value of 'intProperty'",                     new Integer(123),                     (Integer) map.get("intProperty"));        assertEquals("Value of 'longProperty'",                     new Long(321),                     (Long) map.get("longProperty"));        assertEquals("Value of 'shortProperty'",                     new Short((short) 987),                     (Short) map.get("shortProperty"));        assertEquals("Value of 'stringProperty'",                     "This is a string",                     (String) map.get("stringProperty"));    }    /**     * Test populate() method on array properties as a whole.     */    public void testPopulateArrayProperties() {        try {            HashMap map = new HashMap();            //            int intArray[] = new int[] { 123, 456, 789 };            String intArrayIn[] = new String[] { "123", "456", "789" };            map.put("intArray", intArrayIn);            String stringArray[] = new String[]                { "New String 0", "New String 1" };            map.put("stringArray", stringArray);            BeanUtils.populate(bean, map);            int intArray[] = (int[]) bean.get("intArray");            assertNotNull("intArray is present", intArray);            assertEquals("intArray length",                         3, intArray.length);            assertEquals("intArray[0]", 123, intArray[0]);            assertEquals("intArray[1]", 456, intArray[1]);            assertEquals("intArray[2]", 789, intArray[2]);            stringArray = (String[]) bean.get("stringArray");            assertNotNull("stringArray is present", stringArray);            assertEquals("stringArray length", 2, stringArray.length);            assertEquals("stringArray[0]", "New String 0", stringArray[0]);            assertEquals("stringArray[1]", "New String 1", stringArray[1]);        } catch (IllegalAccessException e) {            fail("IllegalAccessException");        } catch (InvocationTargetException e) {            fail("InvocationTargetException");        }    }    /**     *  tests the string and int arrays of TestBean     */    public void testGetArrayProperty() {        try {            String arr[] = BeanUtils.getArrayProperty(bean, "stringArray");            String comp[] = (String[]) bean.get("stringArray");            assertTrue("String array length = " + comp.length,                    (comp.length == arr.length));            arr = BeanUtils.getArrayProperty(bean, "intArray");            int iarr[] = (int[]) bean.get("intArray");            assertTrue("String array length = " + iarr.length,                    (iarr.length == arr.length));        } catch (IllegalAccessException e) {            fail("IllegalAccessException");        } catch (InvocationTargetException e) {            fail("InvocationTargetException");        } catch (NoSuchMethodException e) {            fail("NoSuchMethodException");        }    }    /**     *  tests getting an indexed property     */    public void testGetIndexedProperty1() {        try {            String val = BeanUtils.getIndexedProperty(bean, "intIndexed[3]");            String comp = String.valueOf(bean.get("intIndexed", 3));            assertTrue("intIndexed[3] == " + comp, val.equals(comp));            val = BeanUtils.getIndexedProperty(bean, "stringIndexed[3]");            comp = (String) bean.get("stringIndexed", 3);            assertTrue("stringIndexed[3] == " + comp, val.equals(comp));        } catch (IllegalAccessException e) {            fail("IllegalAccessException");        } catch (InvocationTargetException e) {            fail("InvocationTargetException");        } catch (NoSuchMethodException e) {            fail("NoSuchMethodException");        }    }    /**     *  tests getting an indexed property     */    public void testGetIndexedProperty2() {        try {            String val = BeanUtils.getIndexedProperty(bean, "intIndexed", 3);            String comp = String.valueOf(bean.get("intIndexed", 3));            assertTrue("intIndexed,3 == " + comp, val.equals(comp));            val = BeanUtils.getIndexedProperty(bean, "stringIndexed", 3);            comp = (String) bean.get("stringIndexed", 3);            assertTrue("stringIndexed,3 == " + comp, val.equals(comp));        } catch (IllegalAccessException e) {            fail("IllegalAccessException");        } catch (InvocationTargetException e) {            fail("InvocationTargetException");        } catch (NoSuchMethodException e) {            fail("NoSuchMethodException");        }    }    /**     *  tests getting a nested property     */    public void testGetNestedProperty() {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -