use of java.lang.reflect.AccessibleObject in project robovm by robovm.
the class AccessibleObjectTest method test_isAccessible.
/**
* java.lang.reflect.AccessibleObject#isAccessible()
*/
public void test_isAccessible() {
// java.lang.reflect.AccessibleObject.isAccessible()
try {
AccessibleObject ao = TestClass.class.getField("aField");
ao.setAccessible(true);
assertTrue("Returned false to isAccessible", ao.isAccessible());
ao.setAccessible(false);
assertTrue("Returned true to isAccessible", !ao.isAccessible());
} catch (Exception e) {
fail("Exception during test : " + e.getMessage());
}
}
use of java.lang.reflect.AccessibleObject in project robovm by robovm.
the class AccessibleObjectTest method test_getDeclaredAnnotations.
public void test_getDeclaredAnnotations() throws Exception {
AccessibleObject ao = SubTestClass.class.getMethod("annotatedMethod");
Annotation[] annotations = ao.getDeclaredAnnotations();
assertEquals(2, annotations.length);
Set<Class<?>> ignoreOrder = new HashSet<Class<?>>();
ignoreOrder.add(annotations[0].annotationType());
ignoreOrder.add(annotations[1].annotationType());
assertTrue("Missing @AnnotationRuntime0", ignoreOrder.contains(AnnotationRuntime0.class));
assertTrue("Missing @AnnotationRuntime1", ignoreOrder.contains(AnnotationRuntime1.class));
}
use of java.lang.reflect.AccessibleObject in project robovm by robovm.
the class AccessibleObjectTest method test_getAnnotation.
public void test_getAnnotation() throws Exception {
AccessibleObject ao = SubTestClass.class.getMethod("annotatedMethod");
//test error case
boolean npeThrown = false;
try {
ao.getAnnotation(null);
fail("NPE expected");
} catch (NullPointerException e) {
npeThrown = true;
}
assertTrue("NPE expected", npeThrown);
//test inherited on method has no effect
InheritedRuntime ir = ao.getAnnotation(InheritedRuntime.class);
assertNull("Inherited Annotations should have no effect", ir);
//test ordinary runtime annotation
AnnotationRuntime0 rt0 = ao.getAnnotation(AnnotationRuntime0.class);
assertNotNull("AnnotationRuntime0 instance expected", rt0);
}
use of java.lang.reflect.AccessibleObject in project robovm by robovm.
the class AccessibleObjectTest method test_setAccessible$Ljava_lang_reflect_AccessibleObjectZ.
/**
* java.lang.reflect.AccessibleObject#setAccessible(java.lang.reflect.AccessibleObject[],
* boolean)
*/
public void test_setAccessible$Ljava_lang_reflect_AccessibleObjectZ() {
try {
AccessibleObject ao = TestClass.class.getField("aField");
AccessibleObject[] aoa = new AccessibleObject[] { ao };
AccessibleObject.setAccessible(aoa, true);
assertTrue("Returned false to isAccessible", ao.isAccessible());
AccessibleObject.setAccessible(aoa, false);
assertTrue("Returned true to isAccessible", !ao.isAccessible());
} catch (Exception e) {
fail("Exception during test : " + e.getMessage());
}
}
use of java.lang.reflect.AccessibleObject in project spring-framework by spring-projects.
the class RmiSupportTests method remoteInvocation.
@Test
public void remoteInvocation() throws NoSuchMethodException {
// let's see if the remote invocation object works
final RemoteBean rb = new RemoteBean();
final Method setNameMethod = rb.getClass().getDeclaredMethod("setName", String.class);
MethodInvocation mi = new MethodInvocation() {
@Override
public Method getMethod() {
return setNameMethod;
}
@Override
public Object[] getArguments() {
return new Object[] { "bla" };
}
@Override
public Object proceed() throws Throwable {
throw new UnsupportedOperationException();
}
@Override
public Object getThis() {
return rb;
}
@Override
public AccessibleObject getStaticPart() {
return setNameMethod;
}
};
RemoteInvocation inv = new RemoteInvocation(mi);
assertEquals("setName", inv.getMethodName());
assertEquals("bla", inv.getArguments()[0]);
assertEquals(String.class, inv.getParameterTypes()[0]);
// this is a bit BS, but we need to test it
inv = new RemoteInvocation();
inv.setArguments(new Object[] { "bla" });
assertEquals("bla", inv.getArguments()[0]);
inv.setMethodName("setName");
assertEquals("setName", inv.getMethodName());
inv.setParameterTypes(new Class<?>[] { String.class });
assertEquals(String.class, inv.getParameterTypes()[0]);
inv = new RemoteInvocation("setName", new Class<?>[] { String.class }, new Object[] { "bla" });
assertEquals("bla", inv.getArguments()[0]);
assertEquals("setName", inv.getMethodName());
assertEquals(String.class, inv.getParameterTypes()[0]);
}
Aggregations