use of java.beans.IntrospectionException in project j2objc by google.
the class FakeFox01BeanInfo method getPropertyDescriptors.
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
PropertyDescriptor propertyDesc = null;
try {
propertyDesc = new PropertyDescriptor("fox01", clazz);
propertyDesc.setDisplayName(propertyDesc.getDisplayName() + suffix);
} catch (IntrospectionException e) {
e.printStackTrace();
}
return new PropertyDescriptor[] { propertyDesc };
}
use of java.beans.IntrospectionException in project j2objc by google.
the class PropertyDescriptorTest method testPropertyDescriptorStringClass.
/*
* Class under test for void PropertyDescriptor(String, Class)
*/
public void testPropertyDescriptorStringClass() throws IntrospectionException {
String propertyName = "propertyOne";
Class<MockJavaBean> beanClass = MockJavaBean.class;
PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass);
String capitalName = propertyName.substring(0, 1).toUpperCase() + propertyName.substring(1);
assertEquals(String.class, pd.getPropertyType());
assertEquals("get" + capitalName, pd.getReadMethod().getName());
assertEquals("set" + capitalName, pd.getWriteMethod().getName());
assertFalse(pd.isBound());
assertFalse(pd.isConstrained());
assertEquals(propertyName, pd.getDisplayName());
assertEquals(propertyName, pd.getName());
assertEquals(propertyName, pd.getShortDescription());
assertNotNull(pd.attributeNames());
assertFalse(pd.isExpert());
assertFalse(pd.isHidden());
assertFalse(pd.isPreferred());
propertyName = "propertyWithoutGet";
try {
new PropertyDescriptor(propertyName, beanClass);
fail("Should throw IntrospectionException");
} catch (IntrospectionException e) {
}
try {
new PropertyDescriptor(propertyName, beanClass, "getPropertyWithoutGet", "setPropertyWithoutGet");
fail("Should throw IntrospectionException");
} catch (IntrospectionException e) {
}
propertyName = "propertyWithoutSet";
beanClass = MockJavaBean.class;
try {
new PropertyDescriptor(propertyName, beanClass);
fail("Should throw IntrospectionException");
} catch (IntrospectionException e) {
}
propertyName = "propertyWithDifferentGetSet";
try {
new PropertyDescriptor(propertyName, beanClass);
fail("Should throw IntrospectionException");
} catch (IntrospectionException e) {
}
propertyName = "propertyWithInvalidGet";
new PropertyDescriptor(propertyName, beanClass);
propertyName = "propertyWithoutPublicGet";
try {
new PropertyDescriptor(propertyName, beanClass);
fail("Should throw IntrospectionException");
} catch (IntrospectionException e) {
}
propertyName = "propertyWithGet1Param";
try {
new PropertyDescriptor(propertyName, beanClass);
fail("Should throw IntrospectionException");
} catch (IntrospectionException e) {
}
propertyName = "propertyWithIs1Param";
PropertyDescriptor pd2 = new PropertyDescriptor(propertyName, beanClass);
assertEquals("getPropertyWithIs1Param", pd2.getReadMethod().getName());
propertyName = "propertyWithSet2Param";
try {
new PropertyDescriptor(propertyName, beanClass);
fail("Should throw IntrospectionException");
} catch (IntrospectionException e) {
}
propertyName = "propertyWithIsGet";
PropertyDescriptor pd3 = new PropertyDescriptor(propertyName, beanClass);
assertEquals("isPropertyWithIsGet", pd3.getReadMethod().getName());
propertyName = "propertyWithVoidGet";
try {
new PropertyDescriptor(propertyName, beanClass);
fail("Should throw IntrospectionException");
} catch (IntrospectionException e) {
}
}
use of java.beans.IntrospectionException in project j2objc by google.
the class PropertyDescriptorTest method testSetWriteMethod_Invalid_NoArgs.
/**
* write method without argument
*/
public void testSetWriteMethod_Invalid_NoArgs() throws SecurityException, NoSuchMethodException, IntrospectionException {
Class<MockJavaBean> beanClass = MockJavaBean.class;
String propertyName = "PropertyOne";
Method writeMethod = beanClass.getMethod("get" + "PropertyTwo", (Class[]) null);
PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);
assertNull(pd.getWriteMethod());
try {
pd.setWriteMethod(writeMethod);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
use of java.beans.IntrospectionException in project j2objc by google.
the class PropertyDescriptorTest method testSetReadMethod_Invalid_withArg.
/**
* String invalidGetMethod(String arg)
*/
public void testSetReadMethod_Invalid_withArg() throws SecurityException, NoSuchMethodException, IntrospectionException {
Class<MockJavaBean> beanClass = MockJavaBean.class;
String propertyName = "PropertyOne";
Method readMethod = beanClass.getMethod("invalidGetMethod", new Class[] { String.class });
PropertyDescriptor pd = new PropertyDescriptor(propertyName, null, null);
assertNull(pd.getReadMethod());
try {
pd.setReadMethod(readMethod);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
use of java.beans.IntrospectionException in project cobar by alibaba.
the class ParameterMapping method getDescriptors.
private static PropertyDescriptor[] getDescriptors(Class<?> clazz) {
PropertyDescriptor[] pds;
List<PropertyDescriptor> list;
PropertyDescriptor[] pds2 = descriptors.get(clazz);
if (null == pds2) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
pds = beanInfo.getPropertyDescriptors();
list = new ArrayList<PropertyDescriptor>();
for (int i = 0; i < pds.length; i++) {
if (null != pds[i].getPropertyType()) {
list.add(pds[i]);
}
}
pds2 = new PropertyDescriptor[list.size()];
list.toArray(pds2);
} catch (IntrospectionException ie) {
ie.printStackTrace();
pds2 = new PropertyDescriptor[0];
}
}
descriptors.put(clazz, pds2);
return (pds2);
}
Aggregations