vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java
branchreflection
changeset 655 044c72732424
parent 649 4b16b7e23cab
child 661 66e080030577
     1.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java	Sun Feb 03 08:01:48 2013 +0100
     1.2 +++ b/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionTest.java	Sun Feb 03 23:18:47 2013 +0100
     1.3 @@ -17,6 +17,8 @@
     1.4   */
     1.5  package org.apidesign.bck2brwsr.tck;
     1.6  
     1.7 +import java.lang.annotation.Retention;
     1.8 +import java.lang.annotation.RetentionPolicy;
     1.9  import java.lang.reflect.Method;
    1.10  import java.util.Arrays;
    1.11  import java.util.Collections;
    1.12 @@ -67,6 +69,19 @@
    1.13          }
    1.14          return sb.toString();
    1.15      }
    1.16 +
    1.17 +    @Compare public String namesOfDeclaringClassesOfMethods() {
    1.18 +        StringBuilder sb = new StringBuilder();
    1.19 +        String[] arr = new String[20];
    1.20 +        int i = 0;
    1.21 +        for (Method m : StaticUse.class.getMethods()) {
    1.22 +            arr[i++] = m.getName() + "@" + m.getDeclaringClass().getName();
    1.23 +        }
    1.24 +        for (String s : sort(arr, i)) {
    1.25 +            sb.append(s).append("\n");
    1.26 +        }
    1.27 +        return sb.toString();
    1.28 +    }
    1.29      
    1.30      @Compare public String cannotCallNonStaticMethodWithNull() throws Exception {
    1.31          StaticUse.class.getMethod("instanceMethod").invoke(null);
    1.32 @@ -77,6 +92,17 @@
    1.33          return StaticUse.class.getMethod("instanceMethod").getReturnType();
    1.34      }
    1.35      
    1.36 +    @Retention(RetentionPolicy.RUNTIME)
    1.37 +    @interface Ann {
    1.38 +    }
    1.39 +    
    1.40 +    @Compare public String annoClass() throws Exception {
    1.41 +        Retention r = Ann.class.getAnnotation(Retention.class);
    1.42 +        assert r != null : "Annotation is present";
    1.43 +        assert r.value() == RetentionPolicy.RUNTIME : "Policy value is OK: " + r.value();
    1.44 +        return r.annotationType().getName();
    1.45 +    }
    1.46 +    
    1.47      enum E { A, B };
    1.48      @Compare public boolean isEnum() {
    1.49          return E.A.getClass().isEnum();