|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2020 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
25 | 25 | import java.lang.annotation.Target;
|
26 | 26 | import java.lang.reflect.AnnotatedElement;
|
27 | 27 | import java.util.Set;
|
| 28 | +import java.util.stream.Stream; |
28 | 29 |
|
29 | 30 | import org.assertj.core.api.ThrowableTypeAssert;
|
30 | 31 | import org.junit.jupiter.api.Test;
|
@@ -222,14 +223,35 @@ void typeHierarchyAnnotationsWhenNoninheritedComposedRepeatableOnSuperclassRetur
|
222 | 223 | "B", "C");
|
223 | 224 | }
|
224 | 225 |
|
225 |
| - private <A extends Annotation> Set<A> getAnnotations( |
226 |
| - Class<? extends Annotation> container, Class<A> repeatable, |
227 |
| - SearchStrategy searchStrategy, AnnotatedElement element) { |
| 226 | + @Test |
| 227 | + void typeHierarchyAnnotationsWithLocalComposedAnnotationWhoseRepeatableMetaAnnotationsAreFiltered() { |
| 228 | + Class<WithRepeatedMetaAnnotationsClass> element = WithRepeatedMetaAnnotationsClass.class; |
| 229 | + SearchStrategy searchStrategy = SearchStrategy.TYPE_HIERARCHY; |
| 230 | + AnnotationFilter annotationFilter = PeteRepeat.class.getName()::equals; |
| 231 | + |
| 232 | + Set<PeteRepeat> annotations = getAnnotations(null, PeteRepeat.class, searchStrategy, element, annotationFilter); |
| 233 | + assertThat(annotations).isEmpty(); |
| 234 | + |
| 235 | + MergedAnnotations mergedAnnotations = MergedAnnotations.from(element, searchStrategy, |
| 236 | + RepeatableContainers.standardRepeatables(), annotationFilter); |
| 237 | + Stream<Class<? extends Annotation>> annotationTypes = mergedAnnotations.stream() |
| 238 | + .map(MergedAnnotation::synthesize) |
| 239 | + .map(Annotation::annotationType); |
| 240 | + assertThat(annotationTypes).containsExactly(WithRepeatedMetaAnnotations.class, Noninherited.class, Noninherited.class); |
| 241 | + } |
| 242 | + |
| 243 | + private <A extends Annotation> Set<A> getAnnotations(Class<? extends Annotation> container, |
| 244 | + Class<A> repeatable, SearchStrategy searchStrategy, AnnotatedElement element) { |
| 245 | + |
| 246 | + return getAnnotations(container, repeatable, searchStrategy, element, AnnotationFilter.PLAIN); |
| 247 | + } |
| 248 | + |
| 249 | + private <A extends Annotation> Set<A> getAnnotations(Class<? extends Annotation> container, |
| 250 | + Class<A> repeatable, SearchStrategy searchStrategy, AnnotatedElement element, AnnotationFilter annotationFilter) { |
| 251 | + |
228 | 252 | RepeatableContainers containers = RepeatableContainers.of(repeatable, container);
|
229 |
| - MergedAnnotations annotations = MergedAnnotations.from(element, |
230 |
| - searchStrategy, containers, AnnotationFilter.PLAIN); |
231 |
| - return annotations.stream(repeatable).collect( |
232 |
| - MergedAnnotationCollectors.toAnnotationSet()); |
| 253 | + MergedAnnotations annotations = MergedAnnotations.from(element, searchStrategy, containers, annotationFilter); |
| 254 | + return annotations.stream(repeatable).collect(MergedAnnotationCollectors.toAnnotationSet()); |
233 | 255 | }
|
234 | 256 |
|
235 | 257 | private void nonRepeatableRequirements(Exception ex) {
|
@@ -414,4 +436,17 @@ static class SubNoninheritedRepeatableClass extends NoninheritedRepeatableClass
|
414 | 436 |
|
415 | 437 | }
|
416 | 438 |
|
| 439 | + @Retention(RetentionPolicy.RUNTIME) |
| 440 | + @PeteRepeat("A") |
| 441 | + @PeteRepeat("B") |
| 442 | + @interface WithRepeatedMetaAnnotations { |
| 443 | + } |
| 444 | + |
| 445 | + @WithRepeatedMetaAnnotations |
| 446 | + @PeteRepeat("C") |
| 447 | + @Noninherited("X") |
| 448 | + @Noninherited("Y") |
| 449 | + static class WithRepeatedMetaAnnotationsClass { |
| 450 | + } |
| 451 | + |
417 | 452 | }
|
0 commit comments