Search in sources :

Example 6 with AccessibleObject

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());
    }
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject)

Example 7 with AccessibleObject

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));
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet)

Example 8 with AccessibleObject

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);
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject)

Example 9 with AccessibleObject

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());
    }
}
Also used : AccessibleObject(java.lang.reflect.AccessibleObject)

Example 10 with AccessibleObject

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]);
}
Also used : RemoteInvocation(org.springframework.remoting.support.RemoteInvocation) MethodInvocation(org.aopalliance.intercept.MethodInvocation) AccessibleObject(java.lang.reflect.AccessibleObject) Method(java.lang.reflect.Method) Test(org.junit.Test)

Aggregations

AccessibleObject (java.lang.reflect.AccessibleObject)51 ArrayList (java.util.ArrayList)17 Method (java.lang.reflect.Method)13 Field (java.lang.reflect.Field)9 Annotation (java.lang.annotation.Annotation)7 PropertyModel (org.qi4j.runtime.property.PropertyModel)6 HashSet (java.util.HashSet)5 Property (org.qi4j.api.property.Property)4 BuilderEntityState (org.qi4j.runtime.unitofwork.BuilderEntityState)4 MethodInvocation (org.aopalliance.intercept.MethodInvocation)3 MetaInfo (org.qi4j.api.common.MetaInfo)3 Optional (org.qi4j.api.common.Optional)3 DynamicFinder (com.google.inject.persist.finder.DynamicFinder)2 Finder (com.google.inject.persist.finder.Finder)2 InvocationHandler (java.lang.reflect.InvocationHandler)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 HashMap (java.util.HashMap)2 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)2 ResourceInjectionTargetMetaData (org.jboss.metadata.javaee.spec.ResourceInjectionTargetMetaData)2 Module (org.jboss.modules.Module)2