use of org.apache.harmony.beans.tests.support.mock.MockJavaBean in project j2objc by google.
the class PropertyDescriptorTest method testSetWriteMethod_WriteReadIncompatible.
/**
* write method is incompatible with read method
*/
public void testSetWriteMethod_WriteReadIncompatible() throws SecurityException, NoSuchMethodException, IntrospectionException {
Class<MockJavaBean> beanClass = MockJavaBean.class;
String propertyName = "PropertyOne";
Method readMethod = beanClass.getMethod("get" + "PropertyTwo", (Class[]) null);
Method writeMethod = beanClass.getMethod("set" + propertyName, new Class[] { String.class });
PropertyDescriptor pd = new PropertyDescriptor(propertyName, readMethod, null);
assertNull(pd.getWriteMethod());
try {
pd.setWriteMethod(writeMethod);
fail("Should throw IntrospectionException.");
} catch (IntrospectionException e) {
}
}
use of org.apache.harmony.beans.tests.support.mock.MockJavaBean in project j2objc by google.
the class MethodDescriptorTest method testMethodDescriptorMethod.
/*
* Class under test for void MethodDescriptor(Method)
*/
public void testMethodDescriptorMethod() throws SecurityException, NoSuchMethodException {
String beanName = "MethodDescriptorTest.bean";
MockJavaBean bean = new MockJavaBean(beanName);
Method method = bean.getClass().getMethod("getBeanName", (Class[]) null);
MethodDescriptor md = new MethodDescriptor(method);
assertSame(method, md.getMethod());
assertNull(md.getParameterDescriptors());
assertEquals(method.getName(), md.getDisplayName());
assertEquals(method.getName(), md.getName());
assertEquals(method.getName(), md.getShortDescription());
assertNotNull(md.attributeNames());
assertFalse(md.isExpert());
assertFalse(md.isHidden());
assertFalse(md.isPreferred());
}
use of org.apache.harmony.beans.tests.support.mock.MockJavaBean in project j2objc by google.
the class MethodDescriptorTest method testMethodDescriptorMethodParameterDescriptorArray.
/*
* Class under test for void MethodDescriptor(Method, ParameterDescriptor[])
*/
public void testMethodDescriptorMethodParameterDescriptorArray() throws SecurityException, NoSuchMethodException {
String beanName = "MethodDescriptorTest.bean";
MockJavaBean bean = new MockJavaBean(beanName);
Method method = bean.getClass().getMethod("setPropertyOne", new Class[] { String.class });
ParameterDescriptor[] pds = new ParameterDescriptor[1];
pds[0] = new ParameterDescriptor();
pds[0].setValue(method.getName(), method.getReturnType());
MethodDescriptor md = new MethodDescriptor(method, pds);
assertSame(method, md.getMethod());
assertSame(pds, md.getParameterDescriptors());
assertEquals(pds[0].getValue(method.getName()), md.getParameterDescriptors()[0].getValue(method.getName()));
assertEquals(method.getName(), md.getDisplayName());
assertEquals(method.getName(), md.getName());
assertEquals(method.getName(), md.getShortDescription());
assertNotNull(md.attributeNames());
assertFalse(md.isExpert());
assertFalse(md.isHidden());
assertFalse(md.isPreferred());
}
use of org.apache.harmony.beans.tests.support.mock.MockJavaBean in project j2objc by google.
the class PropertyDescriptorTest method testPropertyDescriptorStringClassStringString_WriteMethodNull.
public void testPropertyDescriptorStringClassStringString_WriteMethodNull() throws IntrospectionException {
String propertyName = "PropertyTwo";
Class<MockJavaBean> beanClass = MockJavaBean.class;
PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass, "get" + propertyName, null);
assertEquals(Integer.class, pd.getPropertyType());
assertEquals("get" + propertyName, pd.getReadMethod().getName());
assertNull(pd.getWriteMethod());
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());
}
use of org.apache.harmony.beans.tests.support.mock.MockJavaBean 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) {
}
}
Aggregations