Search in sources :

Example 1 with SearchStrategy

use of org.springframework.core.annotation.MergedAnnotations.SearchStrategy in project spring-framework by spring-projects.

the class MergedAnnotationsTests method fromPreconditions.

@Test
void fromPreconditions() {
    SearchStrategy strategy = SearchStrategy.DIRECT;
    RepeatableContainers containers = RepeatableContainers.standardRepeatables();
    assertThatIllegalArgumentException().isThrownBy(() -> MergedAnnotations.from(getClass(), strategy, null, AnnotationFilter.PLAIN)).withMessage("RepeatableContainers must not be null");
    assertThatIllegalArgumentException().isThrownBy(() -> MergedAnnotations.from(getClass(), strategy, containers, null)).withMessage("AnnotationFilter must not be null");
    assertThatIllegalArgumentException().isThrownBy(() -> MergedAnnotations.from(getClass(), new Annotation[0], null, AnnotationFilter.PLAIN)).withMessage("RepeatableContainers must not be null");
    assertThatIllegalArgumentException().isThrownBy(() -> MergedAnnotations.from(getClass(), new Annotation[0], containers, null)).withMessage("AnnotationFilter must not be null");
}
Also used : SearchStrategy(org.springframework.core.annotation.MergedAnnotations.SearchStrategy) Test(org.junit.jupiter.api.Test)

Example 2 with SearchStrategy

use of org.springframework.core.annotation.MergedAnnotations.SearchStrategy in project spring-framework by spring-projects.

the class MergedAnnotationsRepeatableAnnotationTests method typeHierarchyAnnotationsWithLocalComposedAnnotationWhoseRepeatableMetaAnnotationsAreFiltered.

@Test
void typeHierarchyAnnotationsWithLocalComposedAnnotationWhoseRepeatableMetaAnnotationsAreFiltered() {
    Class<WithRepeatedMetaAnnotationsClass> element = WithRepeatedMetaAnnotationsClass.class;
    SearchStrategy searchStrategy = SearchStrategy.TYPE_HIERARCHY;
    AnnotationFilter annotationFilter = PeteRepeat.class.getName()::equals;
    Set<PeteRepeat> annotations = getAnnotations(null, PeteRepeat.class, searchStrategy, element, annotationFilter);
    assertThat(annotations).isEmpty();
    MergedAnnotations mergedAnnotations = MergedAnnotations.from(element, searchStrategy, RepeatableContainers.standardRepeatables(), annotationFilter);
    Stream<Class<? extends Annotation>> annotationTypes = mergedAnnotations.stream().map(MergedAnnotation::synthesize).map(Annotation::annotationType);
    assertThat(annotationTypes).containsExactly(WithRepeatedMetaAnnotations.class, Noninherited.class, Noninherited.class);
}
Also used : SearchStrategy(org.springframework.core.annotation.MergedAnnotations.SearchStrategy) Annotation(java.lang.annotation.Annotation) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)2 SearchStrategy (org.springframework.core.annotation.MergedAnnotations.SearchStrategy)2 Annotation (java.lang.annotation.Annotation)1