Search in sources :

Example 1 with SearchStrategy

use of cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy in project today-infrastructure by TAKETODAY.

the class MergedAnnotationsTests method fromPreconditions.

@Test
void fromPreconditions() {
    SearchStrategy strategy = SearchStrategy.DIRECT;
    RepeatableContainers containers = RepeatableContainers.standard();
    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(cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy) Test(org.junit.jupiter.api.Test)

Example 2 with SearchStrategy

use of cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy in project today-infrastructure by TAKETODAY.

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.standard(), 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(cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy) Annotation(java.lang.annotation.Annotation) Test(org.junit.jupiter.api.Test)

Example 3 with SearchStrategy

use of cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy in project today-framework by TAKETODAY.

the class MergedAnnotationsTests method fromPreconditions.

@Test
void fromPreconditions() {
    SearchStrategy strategy = SearchStrategy.DIRECT;
    RepeatableContainers containers = RepeatableContainers.standard();
    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(cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy) Test(org.junit.jupiter.api.Test)

Example 4 with SearchStrategy

use of cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy in project today-framework by TAKETODAY.

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.standard(), 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(cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy) Annotation(java.lang.annotation.Annotation) Test(org.junit.jupiter.api.Test)

Aggregations

SearchStrategy (cn.taketoday.core.annotation.MergedAnnotations.SearchStrategy)4 Test (org.junit.jupiter.api.Test)4 Annotation (java.lang.annotation.Annotation)2