Merge pull request #10504 from alimate/BAEL-4765
BAEL-4765: Update "Java built-in Annotations" article
This commit is contained in:
		
						commit
						ad391e8c24
					
				| @ -0,0 +1,8 @@ | ||||
| package com.baeldung.annotations; | ||||
| 
 | ||||
| import javax.annotation.Generated; | ||||
| 
 | ||||
| @RetentionAnnotation | ||||
| @Generated("Available only on source code") | ||||
| public class AnnotatedClass { | ||||
| } | ||||
| @ -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 { | ||||
| } | ||||
| @ -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)); | ||||
|     } | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user