下面列出了java.beans.IndexedPropertyDescriptor#setIndexedReadMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void testSetIndexedReadMethod() throws SecurityException,
NoSuchMethodException, IntrospectionException {
String propertyName = "PropertyFour";
Class<MockJavaBean> beanClass = MockJavaBean.class;
Method readMethod = beanClass.getMethod("get" + propertyName,
(Class[]) null);
Method writeMethod = beanClass.getMethod("set" + propertyName,
new Class[] { String[].class });
Method indexedReadMethod = beanClass.getMethod("get" + propertyName,
new Class[] { Integer.TYPE });
Method indexedWriteMethod = beanClass.getMethod("set" + propertyName,
new Class[] { Integer.TYPE, String.class });
IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(
propertyName, readMethod, writeMethod, null, indexedWriteMethod);
assertNull(ipd.getIndexedReadMethod());
ipd.setIndexedReadMethod(indexedReadMethod);
assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
}
public void testSetIndexedReadMethod_invalid() throws SecurityException,
NoSuchMethodException, IntrospectionException {
String propertyName = "PropertyFour";
Class<MockJavaBean> beanClass = MockJavaBean.class;
Method indexedReadMethod = beanClass.getMethod("get" + propertyName,
new Class[] { Integer.TYPE });
Method indexedWriteMethod = beanClass.getMethod("set" + propertyName,
new Class[] { Integer.TYPE, String.class });
IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(
propertyName, null, null, indexedReadMethod, indexedWriteMethod);
Method indexedReadMethod2 = beanClass.getMethod("getPropertySix",
new Class[] { Integer.TYPE });
try {
ipd.setIndexedReadMethod(indexedReadMethod2);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
public void testSetIndexedReadMethod_null() throws SecurityException,
NoSuchMethodException, IntrospectionException {
String propertyName = "PropertyFour";
Class<MockJavaBean> beanClass = MockJavaBean.class;
Method readMethod = beanClass.getMethod("get" + propertyName,
(Class[]) null);
Method writeMethod = beanClass.getMethod("set" + propertyName,
new Class[] { String[].class });
Method indexedReadMethod = beanClass.getMethod("get" + propertyName,
new Class[] { Integer.TYPE });
Method indexedWriteMethod = beanClass.getMethod("set" + propertyName,
new Class[] { Integer.TYPE, String.class });
IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(
propertyName, readMethod, writeMethod, indexedReadMethod,
indexedWriteMethod);
assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
ipd.setIndexedReadMethod(null);
assertNull(ipd.getIndexedReadMethod());
}
public void testSetIndexedReadMethod_RInvalidArgs()
throws SecurityException, NoSuchMethodException,
IntrospectionException {
String propertyName = "PropertyFour";
Class<MockJavaBean> beanClass = MockJavaBean.class;
Method readMethod = beanClass.getMethod("get" + propertyName,
(Class[]) null);
Method writeMethod = beanClass.getMethod("set" + propertyName,
new Class[] { String[].class });
Method indexedReadMethod = beanClass.getMethod("get" + propertyName,
new Class[] { Integer.TYPE });
Method indexedWriteMethod = beanClass.getMethod("set" + propertyName,
new Class[] { Integer.TYPE, String.class });
IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(
propertyName, readMethod, writeMethod, indexedReadMethod,
indexedWriteMethod);
assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
try {
ipd.setIndexedReadMethod(readMethod);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
public void testSetIndexedReadMethod_RInvalidArgType()
throws SecurityException, NoSuchMethodException,
IntrospectionException {
String propertyName = "PropertyFour";
Class<MockJavaBean> beanClass = MockJavaBean.class;
Method readMethod = beanClass.getMethod("get" + propertyName,
(Class[]) null);
Method writeMethod = beanClass.getMethod("set" + propertyName,
new Class[] { String[].class });
Method indexedReadMethod = beanClass.getMethod("get" + propertyName,
new Class[] { Integer.TYPE });
Method indexedWriteMethod = beanClass.getMethod("set" + propertyName,
new Class[] { Integer.TYPE, String.class });
IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(
propertyName, readMethod, writeMethod, indexedReadMethod,
indexedWriteMethod);
assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
try {
ipd.setIndexedReadMethod(writeMethod);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
public void testSetIndexedReadMethod_RInvalidReturn()
throws SecurityException, NoSuchMethodException,
IntrospectionException {
String propertyName = "PropertyFour";
Class<MockJavaBean> beanClass = MockJavaBean.class;
Method readMethod = beanClass.getMethod("get" + propertyName,
(Class[]) null);
Method writeMethod = beanClass.getMethod("set" + propertyName,
new Class[] { String[].class });
Method indexedReadMethod = beanClass.getMethod("get" + propertyName,
new Class[] { Integer.TYPE });
Method indexedWriteMethod = beanClass.getMethod("set" + propertyName,
new Class[] { Integer.TYPE, String.class });
IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(
propertyName, readMethod, writeMethod, indexedReadMethod,
indexedWriteMethod);
assertSame(indexedReadMethod, ipd.getIndexedReadMethod());
Method voidMethod = beanClass.getMethod("getPropertyFourInvalid",
new Class[] { Integer.TYPE });
try {
ipd.setIndexedReadMethod(voidMethod);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
public void testSetIndexedReadMethodFollowANullValue() throws Exception {
try {
IndexedPropertyDescriptor i = new IndexedPropertyDescriptor("a",
DummyBean.class, "readMethod", "writeMethod", null,
"indexedReadMethod");
Method irm = DummyBean.class.getDeclaredMethod("indexedReadMethod",
Integer.TYPE);
i.setIndexedReadMethod(irm);
fail("should throw IntrospectionException.");
} catch (IntrospectionException e) {
// expected
}
}