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

📄 propertyutilstestcase.java

📁 apache beanutils开源项目源码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            try {                value = PropertyUtils.getIndexedProperty                    (bean, "dupProperty[" + i + "]");                assertNotNull("dupProperty returned value " + i, value);                assertTrue("dupProperty returned String " + i,                        value instanceof String);                assertEquals("dupProperty returned correct " + i,                             "Dup " + i,                             (String) value);            } catch (Throwable t) {                fail("dupProperty " + i + " threw " + t);            }            try {                value =                        PropertyUtils.getIndexedProperty(bean,                                "intArray[" + i + "]");                assertNotNull("intArray returned value " + i, value);                assertTrue("intArray returned Integer " + i,                        value instanceof Integer);                assertEquals("intArray returned correct " + i, i * 10,                        ((Integer) value).intValue());            } catch (Throwable t) {                fail("intArray " + i + " threw " + t);            }            try {                value =                        PropertyUtils.getIndexedProperty(bean,                                "intIndexed[" + i + "]");                assertNotNull("intIndexed returned value " + i, value);                assertTrue("intIndexed returned Integer " + i,                        value instanceof Integer);                assertEquals("intIndexed returned correct " + i, i * 10,                        ((Integer) value).intValue());            } catch (Throwable t) {                fail("intIndexed " + i + " threw " + t);            }            try {                value =                        PropertyUtils.getIndexedProperty(bean,                                "listIndexed[" + i + "]");                assertNotNull("listIndexed returned value " + i, value);                assertTrue("listIndexed returned String " + i,                        value instanceof String);                assertEquals("listIndexed returned correct " + i,                        "String " + i, (String) value);            } catch (Throwable t) {                fail("listIndexed " + i + " threw " + t);            }            try {                value =                        PropertyUtils.getIndexedProperty(bean,                                "stringArray[" + i + "]");                assertNotNull("stringArray returned value " + i, value);                assertTrue("stringArray returned String " + i,                        value instanceof String);                assertEquals("stringArray returned correct " + i,                        "String " + i, (String) value);            } catch (Throwable t) {                fail("stringArray " + i + " threw " + t);            }            try {                value =                        PropertyUtils.getIndexedProperty(bean,                                "stringIndexed[" + i + "]");                assertNotNull("stringIndexed returned value " + i, value);                assertTrue("stringIndexed returned String " + i,                        value instanceof String);                assertEquals("stringIndexed returned correct " + i,                        "String " + i, (String) value);            } catch (Throwable t) {                fail("stringIndexed " + i + " threw " + t);            }        }        // Index out of bounds tests        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "dupProperty", -1);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "dupProperty", 5);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "intArray", -1);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "intArray", 5);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "intIndexed", -1);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "intIndexed", 5);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "listIndexed", -1);            fail("Should have thrown IndexOutOfBoundsException");        } catch (IndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of IndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "listIndexed", 5);            fail("Should have thrown IndexOutOfBoundsException");        } catch (IndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of IndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "stringArray", -1);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "stringArray", 5);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "stringIndexed", -1);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }        try {            value =                    PropertyUtils.getIndexedProperty(bean,                            "stringIndexed", 5);            fail("Should have thrown ArrayIndexOutOfBoundsException");        } catch (ArrayIndexOutOfBoundsException t) {            ; // Expected results        } catch (Throwable t) {            fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException");        }    }    /**     * Corner cases on getMappedProperty invalid arguments.     */    public void testGetMappedArguments() {        // Use explicit key argument        try {            PropertyUtils.getMappedProperty(null, "mappedProperty",                    "First Key");            fail("Should throw IllegalArgumentException 1");        } catch (IllegalArgumentException e) {            ; // Expected response        } catch (Throwable t) {            fail("Threw " + t + " instead of IllegalArgumentException 1");        }        try {            PropertyUtils.getMappedProperty(bean, null, "First Key");            fail("Should throw IllegalArgumentException 2");        } catch (IllegalArgumentException e) {            ; // Expected response        } catch (Throwable t) {            fail("Threw " + t + " instead of IllegalArgumentException 2");        }        try {            PropertyUtils.getMappedProperty(bean, "mappedProperty", null);            fail("Should throw IllegalArgumentException 3");        } catch (IllegalArgumentException e) {            ; // Expected response        } catch (Throwable t) {            fail("Threw " + t + " instead of IllegalArgumentException 3");        }        // Use key expression        try {            PropertyUtils.getMappedProperty(null,                    "mappedProperty(First Key)");            fail("Should throw IllegalArgumentException 4");        } catch (IllegalArgumentException e) {            ; // Expected response        } catch (Throwable t) {            fail("Threw " + t + " instead of IllegalArgumentException 4");        }        try {            PropertyUtils.getMappedProperty(bean, "(Second Key)");            fail("Should throw IllegalArgumentException 5");        } catch (NoSuchMethodException e) {            ; // Expected response        } catch (Throwable t) {            fail("Threw " + t + " instead of NoSuchMethodException 5");        }        try {            PropertyUtils.getMappedProperty(bean, "mappedProperty");            fail("Should throw IllegalArgumentException 6");        } catch (IllegalArgumentException e) {            ; // Expected response        } catch (Throwable t) {            fail("Threw " + t + " instead of IllegalArgumentException 6");        }    }    /**     * Test getting mapped values with periods in the key.     */    public void testGetMappedPeriods() {        bean.setMappedProperty("key.with.a.dot", "Special Value");        assertEquals("Can retrieve directly",                     "Special Value",                     bean.getMappedProperty("key.with.a.dot"));        try {            assertEquals("Can retrieve via getMappedProperty",                         "Special Value",                         PropertyUtils.getMappedProperty                         (bean, "mappedProperty", "key.with.a.dot"));        } catch (Exception e) {            fail("Thew exception: " + e);        }        try {            assertEquals("Can retrieve via getNestedProperty",                         "Special Value",                         PropertyUtils.getNestedProperty                         (bean, "mappedProperty(key.with.a.dot)"));        } catch (Exception e) {            fail("Thew exception: " + e);        }        bean.setMappedObjects("nested.property", new TestBean());        assertNotNull("Can retrieve directly",                      bean.getMappedObjects("nested.property"));        try {            assertEquals("Can retrieve nested",                         "This is a string",                         PropertyUtils.getNestedProperty                         (bean,                          "mappedObjects(nested.property).stringProperty"));        } catch (Exception e) {            fail("Thew exception: " + e);        }        try         {            assertEquals("Can't retrieved nested with mapped property",                         "Mapped Value",                         PropertyUtils.getNestedProperty(                             bean,"mappedNested.value(Mapped Key)"));        } catch (Exception e)         {            fail("Thew exception: " + e);        }     }    /**     * Test getting mapped values with slashes in the key.  This is different     * from periods because slashes are not syntactically significant.     */    public void testGetMappedSlashes() {        bean.setMappedProperty("key/with/a/slash", "Special Value");        assertEquals("Can retrieve directly",                     "Special Value",                     bean.getMappedProperty("key/with/a/slash"));        try {            assertEquals("Can retrieve via getMappedProperty",                         "Special Value",                         PropertyUtils.getMappedProperty                         (bean, "mappedProperty", "key/with/a/slash"));        } catch (Exception e) {            fail("Thew exception: " + e);        }        try {            assertEquals("Can retrieve via getNestedProperty",                         "Special Value",                         PropertyUtils.getNestedProperty                         (bean, "mappedProperty(key/with/a/slash)"));        } catch (Exception e) {            fail("Thew exception: " + e);        }        bean.setMappedObjects("nested/property", new TestBean());        assertNotNull("Can retrieve directly",                      bean.getMappedObjects("nested/property"));        try {            assertEquals("Can retrieve nested",                         "This is a string",                         PropertyUtils.getNestedProperty                         (bean,                          "mappedObjects(nested/property).stringProperty"));        } catch (Exception e) {            fail("Thew exception: " + e);        }    }

⌨️ 快捷键说明

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