Merge pull request #10504 from alimate/BAEL-4765

BAEL-4765: Update "Java built-in Annotations" article
This commit is contained in:
Eric Martin 2021-02-24 19:07:11 -06:00 committed by GitHub
commit ad391e8c24
3 changed files with 38 additions and 0 deletions

View File

@ -0,0 +1,8 @@
package com.baeldung.annotations;
import javax.annotation.Generated;
@RetentionAnnotation
@Generated("Available only on source code")
public class AnnotatedClass {
}

View File

@ -0,0 +1,12 @@
package com.baeldung.annotations;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.TYPE;
@Target(TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface RetentionAnnotation {
}

View File

@ -0,0 +1,18 @@
package com.baeldung.annotations;
import org.junit.Test;
import java.lang.annotation.Annotation;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class AnnotatedClassUnitTest {
@Test
public void whenAnnotationRetentionPolicyRuntime_shouldAccess() {
AnnotatedClass anAnnotatedClass = new AnnotatedClass();
Annotation[] annotations = anAnnotatedClass.getClass().getAnnotations();
assertThat(annotations.length, is(1));
}
}