📄 indexedpropertytestcase.java
字号:
*/
public void testListIndexedWriteMethod() {
try {
IndexedPropertyDescriptor descriptor =
(IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "stringList");
assertNotNull("No List Indexed Write Method", descriptor.getIndexedWriteMethod());
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test Read Method for an ArrayList
*/
public void testArrayListReadMethod() {
try {
IndexedPropertyDescriptor descriptor =
(IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "arrayList");
assertNotNull("No ArrayList Read Method", descriptor.getReadMethod());
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test Write Method for an ArrayList
*/
public void testArrayListWriteMethod() {
try {
IndexedPropertyDescriptor descriptor =
(IndexedPropertyDescriptor)propertyUtilsBean.getPropertyDescriptor(bean, "arrayList");
assertNotNull("No ArrayList Write Method", descriptor.getWriteMethod());
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting an array property
*/
public void testGetArray() {
try {
assertEquals(testArray,
propertyUtilsBean.getProperty(bean, "stringArray"));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting an array property as a String
*
* NOTE: Why does retrieving array just return the first element in the array, whereas
* retrieveing a List returns a comma separated list of all the elements?
*/
public void testGetArrayAsString() {
try {
assertEquals("array-0",
beanUtilsBean.getProperty(bean, "stringArray"));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting an indexed item of an Array using getProperty("name[x]")
*/
public void testGetArrayItemA() {
try {
assertEquals("array-1",
beanUtilsBean.getProperty(bean, "stringArray[1]"));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting an indexed item of an Array using getIndexedProperty("name")
*/
public void testGetArrayItemB() {
try {
assertEquals("array-1",
beanUtilsBean.getIndexedProperty(bean, "stringArray", 1));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting a List
*
* JDK 1.3.1_04: Test Passes
* JDK 1.4.2_05: Test Fails - fails NoSuchMethodException, i.e. reason as testListReadMethod()
* failed.
*/
public void testGetList() {
try {
assertEquals(testList,
propertyUtilsBean.getProperty(bean, "stringList"));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting a List property as a String
*
* JDK 1.3.1_04: Test Passes
* JDK 1.4.2_05: Test Fails - fails NoSuchMethodException, i.e. reason as testListReadMethod()
* failed.
*/
public void testGetListAsString() {
try {
assertEquals("list-0",
beanUtilsBean.getProperty(bean, "stringList"));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting an indexed item of a List using getProperty("name[x]")
*/
public void testGetListItemA() {
try {
assertEquals("list-1",
beanUtilsBean.getProperty(bean, "stringList[1]"));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting an indexed item of a List using getIndexedProperty("name")
*/
public void testGetListItemB() {
try {
assertEquals("list-1",
beanUtilsBean.getIndexedProperty(bean, "stringList", 1));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test setting an Array property
*
* JDK 1.3.1_04 and 1.4.2_05: Test Fails - IllegalArgumentException can't invoke setter, argument type mismatch
*
* Fails because of a bug in BeanUtilsBean.setProperty() method. Value is always converted to the array's component
* type which in this case is a String. Then it calls the setStringArray(String[]) passing a String rather than
* String[] causing this exception. If there isn't an "index" value then the PropertyType (rather than
* IndexedPropertyType) should be used.
*
*/
public void testSetArray() {
try {
beanUtilsBean.setProperty(bean, "stringArray", newArray);
Object value = bean.getStringArray();
assertEquals("Type is different", newArray.getClass(), value.getClass());
String[] array = (String[])value;
assertEquals("Array Length is different", newArray.length, array.length);
for (int i = 0; i < array.length; i++) {
assertEquals("Element " + i + " is different", newArray[i], array[i]);
}
} catch(Exception e) {
log.error("testSetArray()", e);
fail("Threw exception " + e);
}
}
/**
* Test setting an indexed item of an Array using setProperty("name[x]", value)
*/
public void testSetArrayItemA() {
try {
beanUtilsBean.setProperty(bean, "stringArray[1]", "modified-1");
assertEquals("modified-1", bean.getStringArray(1));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test setting an indexed item of an Array using setIndexedProperty("name", value)
*/
public void testSetArrayItemB() {
try {
propertyUtilsBean.setIndexedProperty(bean, "stringArray", 1, "modified-1");
assertEquals("modified-1", bean.getStringArray(1));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test setting a List property
*
* JDK 1.3.1_04: Test Passes
* JDK 1.4.2_05: Test Fails - setter which returns java.util.List not returned
* by IndexedPropertyDescriptor.getWriteMethod() - therefore
* setProperty does nothing and values remain unchanged.
*/
public void testSetList() {
try {
beanUtilsBean.setProperty(bean, "stringList", newList);
Object value = bean.getStringList();
assertEquals("Type is different", newList.getClass(), value.getClass());
List list = (List)value;
assertEquals("List size is different", newList.size(), list.size());
for (int i = 0; i < list.size(); i++) {
assertEquals("Element " + i + " is different", newList.get(i), list.get(i));
}
} catch(Exception e) {
log.error("testSetList()", e);
fail("Threw exception " + e);
}
}
/**
* Test setting an indexed item of a List using setProperty("name[x]", value)
*/
public void testSetListItemA() {
try {
beanUtilsBean.setProperty(bean, "stringList[1]", "modified-1");
assertEquals("modified-1", bean.getStringList(1));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test setting an indexed item of a List using setIndexedProperty("name", value)
*/
public void testSetListItemB() {
try {
propertyUtilsBean.setIndexedProperty(bean, "stringList", 1, "modified-1");
assertEquals("modified-1", bean.getStringList(1));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test getting an ArrayList
*/
public void testGetArrayList() {
try {
assertEquals(arrayList,
propertyUtilsBean.getProperty(bean, "arrayList"));
} catch(Exception e) {
fail("Threw exception " + e);
}
}
/**
* Test setting an ArrayList property
*/
public void testSetArrayList() {
try {
beanUtilsBean.setProperty(bean, "arrayList", newList);
Object value = bean.getArrayList();
assertEquals("Type is different", newList.getClass(), value.getClass());
List list = (List)value;
assertEquals("List size is different", newList.size(), list.size());
for (int i = 0; i < list.size(); i++) {
assertEquals("Element " + i + " is different", newList.get(i), list.get(i));
}
} catch(Exception e) {
log.error("testSetList()", e);
fail("Threw exception " + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -