📄 dynapropertyutilstestcase.java
字号:
} try { PropertyUtils.setIndexedProperty(bean, "intArray", new Integer(1)); fail("Should throw IllegalArgumentException 5"); } catch (IllegalArgumentException e) { ; // Expected response } catch (Throwable t) { fail("Threw " + t + " instead of IllegalArgumentException 5"); } // Use explicit index argument try { PropertyUtils.setIndexedProperty(null, "intIndexed", 0, new Integer(1)); fail("Should throw IllegalArgumentException 1"); } catch (IllegalArgumentException e) { ; // Expected response } catch (Throwable t) { fail("Threw " + t + " instead of IllegalArgumentException 1"); } try { PropertyUtils.setIndexedProperty(bean, null, 0, new Integer(1)); fail("Should throw IllegalArgumentException 2"); } catch (IllegalArgumentException e) { ; // Expected response } catch (Throwable t) { fail("Threw " + t + " instead of IllegalArgumentException 2"); } // Use index expression try { PropertyUtils.setIndexedProperty(null, "intIndexed[0]", new Integer(1)); fail("Should throw IllegalArgumentException 3"); } catch (IllegalArgumentException e) { ; // Expected response } catch (Throwable t) { fail("Threw " + t + " instead of IllegalArgumentException 3"); } try { PropertyUtils.setIndexedProperty(bean, "[0]", new Integer(1)); fail("Should throw NoSuchMethodException 4"); } catch (NoSuchMethodException e) { ; // Expected response } catch (Throwable t) { fail("Threw " + t + " instead of NoSuchMethodException 4"); } try { PropertyUtils.setIndexedProperty(bean, "intIndexed", new Integer(1)); fail("Should throw IllegalArgumentException 5"); } catch (IllegalArgumentException e) { ; // Expected response } catch (Throwable t) { fail("Threw " + t + " instead of IllegalArgumentException 5"); } } /** * Positive and negative tests on setIndexedProperty valid arguments. */ public void testSetIndexedValues() { Object value = null; // Use explicit index argument try { PropertyUtils.setIndexedProperty(bean, "intArray", 0, new Integer(1)); value = PropertyUtils.getIndexedProperty(bean, "intArray", 0); assertNotNull("Returned new value 0", value); assertTrue("Returned Integer new value 0", value instanceof Integer); assertEquals("Returned correct new value 0", 1, ((Integer) value).intValue()); } catch (Throwable t) { fail("Threw " + t); } try { PropertyUtils.setIndexedProperty(bean, "intIndexed", 1, new Integer(11)); value = PropertyUtils.getIndexedProperty(bean, "intIndexed", 1); assertNotNull("Returned new value 1", value); assertTrue("Returned Integer new value 1", value instanceof Integer); assertEquals("Returned correct new value 1", 11, ((Integer) value).intValue()); } catch (Throwable t) { fail("Threw " + t); } try { PropertyUtils.setIndexedProperty(bean, "listIndexed", 2, "New Value 2"); value = PropertyUtils.getIndexedProperty(bean, "listIndexed", 2); assertNotNull("Returned new value 2", value); assertTrue("Returned String new value 2", value instanceof String); assertEquals("Returned correct new value 2", "New Value 2", (String) value); } catch (Throwable t) { fail("Threw " + t); } try { PropertyUtils.setIndexedProperty(bean, "stringArray", 2, "New Value 2"); value = PropertyUtils.getIndexedProperty(bean, "stringArray", 2); assertNotNull("Returned new value 2", value); assertTrue("Returned String new value 2", value instanceof String); assertEquals("Returned correct new value 2", "New Value 2", (String) value); } catch (Throwable t) { fail("Threw " + t); } try { PropertyUtils.setIndexedProperty(bean, "stringArray", 3, "New Value 3"); value = PropertyUtils.getIndexedProperty(bean, "stringArray", 3); assertNotNull("Returned new value 3", value); assertTrue("Returned String new value 3", value instanceof String); assertEquals("Returned correct new value 3", "New Value 3", (String) value); } catch (Throwable t) { fail("Threw " + t); } // Use index expression try { PropertyUtils.setIndexedProperty(bean, "intArray[4]", new Integer(1)); value = PropertyUtils.getIndexedProperty(bean, "intArray[4]"); assertNotNull("Returned new value 4", value); assertTrue("Returned Integer new value 4", value instanceof Integer); assertEquals("Returned correct new value 4", 1, ((Integer) value).intValue()); } catch (Throwable t) { fail("Threw " + t); } try { PropertyUtils.setIndexedProperty(bean, "intIndexed[3]", new Integer(11)); value = PropertyUtils.getIndexedProperty(bean, "intIndexed[3]"); assertNotNull("Returned new value 5", value); assertTrue("Returned Integer new value 5", value instanceof Integer); assertEquals("Returned correct new value 5", 11, ((Integer) value).intValue()); } catch (Throwable t) { fail("Threw " + t); } try { PropertyUtils.setIndexedProperty(bean, "listIndexed[1]", "New Value 2"); value = PropertyUtils.getIndexedProperty(bean, "listIndexed[1]"); assertNotNull("Returned new value 6", value); assertTrue("Returned String new value 6", value instanceof String); assertEquals("Returned correct new value 6", "New Value 2", (String) value); } catch (Throwable t) { fail("Threw " + t); } try { PropertyUtils.setIndexedProperty(bean, "stringArray[1]", "New Value 2"); value = PropertyUtils.getIndexedProperty(bean, "stringArray[2]"); assertNotNull("Returned new value 6", value); assertTrue("Returned String new value 6", value instanceof String); assertEquals("Returned correct new value 6", "New Value 2", (String) value); } catch (Throwable t) { fail("Threw " + t); } try { PropertyUtils.setIndexedProperty(bean, "stringArray[0]", "New Value 3"); value = PropertyUtils.getIndexedProperty(bean, "stringArray[0]"); assertNotNull("Returned new value 7", value); assertTrue("Returned String new value 7", value instanceof String); assertEquals("Returned correct new value 7", "New Value 3", (String) value); } catch (Throwable t) { fail("Threw " + t); } // Index out of bounds tests try { PropertyUtils.setIndexedProperty(bean, "intArray", -1, new Integer(0)); fail("Should have thrown ArrayIndexOutOfBoundsException"); } catch (ArrayIndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "intArray", 5, new Integer(0)); fail("Should have thrown ArrayIndexOutOfBoundsException"); } catch (ArrayIndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "intIndexed", -1, new Integer(0)); fail("Should have thrown ArrayIndexOutOfBoundsException"); } catch (ArrayIndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "intIndexed", 5, new Integer(0)); fail("Should have thrown ArrayIndexOutOfBoundsException"); } catch (ArrayIndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "listIndexed", 5, "New String"); fail("Should have thrown IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of IndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "listIndexed", -1, "New String"); fail("Should have thrown IndexOutOfBoundsException"); } catch (IndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of IndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "stringArray", -1, "New String"); fail("Should have thrown ArrayIndexOutOfBoundsException"); } catch (ArrayIndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "stringArray", 5, "New String"); fail("Should have thrown ArrayIndexOutOfBoundsException"); } catch (ArrayIndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "stringIndexed", -1, "New String"); fail("Should have thrown ArrayIndexOutOfBoundsException"); } catch (ArrayIndexOutOfBoundsException t) { ; // Expected results } catch (Throwable t) { fail("Threw " + t + " instead of ArrayIndexOutOfBoundsException"); } try { PropertyUtils.setIndexedProperty(bean, "stringIndexed", 5, "New String"); 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 testSetMappedArguments() { // Use explicit key argument try { PropertyUtils.setMappedProperty(null, "mappedProperty", "First Key", "First Value"); fail("Should throw IllegalArgumentException 1"); } catch (IllegalArgumentException e) { ; // Expected response } catch (Throwable t) { fail("Threw " + t + " instead of IllegalArgumentException 1"); } try { PropertyUtils.setMappedProperty(bean, null, "First Key",
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -