rt/emul/compacttest/src/test/java/org/apidesign/bck2brwsr/tck/ReflectionAnnotationTest.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012-2015 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.tck;
20 import java.lang.annotation.Retention;
21 import java.lang.annotation.RetentionPolicy;
22 import org.apidesign.bck2brwsr.vmtest.Compare;
23 import org.apidesign.bck2brwsr.vmtest.VMTest;
24 import org.testng.annotations.Factory;
28 * @author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
30 public class ReflectionAnnotationTest {
31 @Retention(RetentionPolicy.RUNTIME)
33 int integer() default 33;
34 double dbl() default 33.3;
35 String string() default "Ahoj";
36 E enums() default E.B;
37 Class<?> type() default String.class;
41 Ann ann() default @Ann(
54 @Ann(type = String.class)
55 @AnnAnn(ann = @Ann(string = "Ciao"))
61 @Compare public String annoClass() throws Exception {
62 Retention r = Ann.class.getAnnotation(Retention.class);
63 assert r != null : "Annotation is present";
64 assert r.value() == RetentionPolicy.RUNTIME : "Policy value is OK: " + r.value();
65 return r.annotationType().getName();
68 @Compare public boolean isAnnotation() {
69 return Ann.class.isAnnotation();
71 @Compare public boolean isNotAnnotation() {
72 return String.class.isAnnotation();
74 @Compare public boolean isNotAnnotationEnum() {
75 return E.class.isAnnotation();
78 @Compare public int intDefaultAttrIsRead() {
79 return D.class.getAnnotation(Ann.class).integer();
82 @Compare public double doubleDefaultAttrIsRead() {
83 return D.class.getAnnotation(Ann.class).dbl();
86 @Compare public String stringDefaultAttrIsRead() {
87 return D.class.getAnnotation(Ann.class).string();
90 @Compare public String enumDefaultAttrIsRead() {
91 return D.class.getAnnotation(Ann.class).enums().toString();
94 @Compare public String classDefaultAttrIsRead() {
95 return D.class.getAnnotation(Ann.class).type().getName();
98 @Compare public String classAttrIsRead() {
99 return E.class.getAnnotation(Ann.class).type().getName();
102 // @Compare public String defaultAnnotationAttrIsRead() {
103 // final Ann ann = D.class.getAnnotation(AnnAnn.class).ann();
104 // return ann.string() + ann.dbl() + ann.enums() + ann.integer() + ann.type();
107 // @Compare public String annotationAttrIsRead() {
108 // final Ann ann = E.class.getAnnotation(AnnAnn.class).ann();
109 // return ann.string();
113 public static Object[] create() {
114 return VMTest.create(ReflectionAnnotationTest.class);