< prev index next >
test/java/lang/annotation/AnnotationVerifier.java
Print this page
*** 25,36 ****
/*
* Create class file using ASM, slightly modified the ASMifier output
*/
! import sun.reflect.annotation.AnnotationType;
import java.lang.annotation.AnnotationFormatError;
import org.testng.annotations.*;
/*
* @test
* @bug 8158510
--- 25,42 ----
/*
* Create class file using ASM, slightly modified the ASMifier output
*/
! import java.lang.annotation.Annotation;
import java.lang.annotation.AnnotationFormatError;
+ import java.lang.annotation.ElementType;
+ import java.lang.annotation.Retention;
+ import java.lang.annotation.RetentionPolicy;
+ import java.lang.annotation.Target;
+ import java.util.Arrays;
+
import org.testng.annotations.*;
/*
* @test
* @bug 8158510
*** 43,63 ****
* @run testng AnnotationVerifier
*/
public class AnnotationVerifier {
@AnnotationWithParameter
@AnnotationWithVoidReturn
! static class BadAnnotation {
}
! @Test
! @ExpectedExceptions(IllegalArgumentException.class)
! public void annotationValidationIAE() {
! AnnotationType.getInstance(AnnotationWithParameter.class);
}
@Test(expectedExceptions = AnnotationFormatError.class)
! public void annotationValidationAFE() {
! BadAnnotation.class.getAnnotation(AnnotationWithVoidReturn.class);
}
}
--- 49,89 ----
* @run testng AnnotationVerifier
*/
public class AnnotationVerifier {
+ @Retention(RetentionPolicy.RUNTIME)
+ @Target(ElementType.TYPE)
+ @interface GoodAnnotation {}
+
@AnnotationWithParameter
@AnnotationWithVoidReturn
! @GoodAnnotation
! static class AnnotationHolder {
! }
!
! @Test(expectedExceptions = AnnotationFormatError.class)
! public void annotationWithParameter() {
! Annotation ann = AnnotationHolder.class.getAnnotation(AnnotationWithParameter.class);
! System.out.println(ann);
}
! @Test(expectedExceptions = AnnotationFormatError.class)
! public void annotationWithVoidReturn() {
! Annotation ann = AnnotationHolder.class.getAnnotation(AnnotationWithVoidReturn.class);
! System.out.println(ann);
! }
!
! @Test(expectedExceptions = AnnotationFormatError.class)
! public void badAnnotations() {
! Annotation[] anns = AnnotationHolder.class.getAnnotations();
! System.out.println(Arrays.toString(anns));
}
@Test(expectedExceptions = AnnotationFormatError.class)
! public void goodAnnotation() {
! // this annotation is good, but since we parse all annotations in bulk,
! // the exception is thrown because of other bad annotations...
! Annotation ann = AnnotationHolder.class.getAnnotation(GoodAnnotation.class);
! System.out.println(ann);
}
}
< prev index next >