Search in sources :

Example 1 with Component

use of org.springframework.core.testfixture.stereotype.Component in project spring-framework by spring-projects.

the class AnnotationUtilsTests method getAnnotationAttributesWithoutAttributeAliases.

@Test
void getAnnotationAttributesWithoutAttributeAliases() {
    Component component = WebController.class.getAnnotation(Component.class);
    assertThat(component).isNotNull();
    AnnotationAttributes attributes = (AnnotationAttributes) getAnnotationAttributes(component);
    assertThat(attributes).isNotNull();
    assertThat(attributes.getString(VALUE)).as("value attribute: ").isEqualTo("webController");
    assertThat(attributes.annotationType()).isEqualTo(Component.class);
}
Also used : AnnotationUtils.getAnnotationAttributes(org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes) Component(org.springframework.core.testfixture.stereotype.Component) Test(org.junit.jupiter.api.Test)

Example 2 with Component

use of org.springframework.core.testfixture.stereotype.Component in project spring-framework by spring-projects.

the class AnnotationUtilsTests method findClassAnnotationOnMetaMetaMetaAnnotatedClass.

@Test
void findClassAnnotationOnMetaMetaMetaAnnotatedClass() {
    Component component = findAnnotation(MetaMetaMetaAnnotatedClass.class, Component.class);
    assertThat(component).as("Should find meta-annotation on meta-annotation on composed annotation on class").isNotNull();
    assertThat(component.value()).isEqualTo("meta2");
}
Also used : Component(org.springframework.core.testfixture.stereotype.Component) Test(org.junit.jupiter.api.Test)

Example 3 with Component

use of org.springframework.core.testfixture.stereotype.Component in project spring-framework by spring-projects.

the class AnnotationUtilsTests method findClassAnnotationFavorsMoreLocallyDeclaredComposedAnnotationsOverInheritedComposedAnnotations.

// @since 4.0.3
@Test
void findClassAnnotationFavorsMoreLocallyDeclaredComposedAnnotationsOverInheritedComposedAnnotations() {
    Component component = findAnnotation(SubSubClassWithInheritedMetaAnnotation.class, Component.class);
    assertThat(component).isNotNull();
    assertThat(component.value()).isEqualTo("meta2");
}
Also used : Component(org.springframework.core.testfixture.stereotype.Component) Test(org.junit.jupiter.api.Test)

Example 4 with Component

use of org.springframework.core.testfixture.stereotype.Component in project spring-framework by spring-projects.

the class AnnotationUtilsTests method findClassAnnotationOnAnnotatedClassWithMissingTargetMetaAnnotation.

@Test
void findClassAnnotationOnAnnotatedClassWithMissingTargetMetaAnnotation() {
    // TransactionalClass is NOT annotated or meta-annotated with @Component
    Component component = findAnnotation(TransactionalClass.class, Component.class);
    assertThat(component).as("Should not find @Component on TransactionalClass").isNull();
}
Also used : Component(org.springframework.core.testfixture.stereotype.Component) Test(org.junit.jupiter.api.Test)

Example 5 with Component

use of org.springframework.core.testfixture.stereotype.Component in project spring-framework by spring-projects.

the class MergedAnnotationsTests method synthesizeFromMapWithoutAttributeAliases.

@Test
void synthesizeFromMapWithoutAttributeAliases() throws Exception {
    Component component = WebController.class.getAnnotation(Component.class);
    assertThat(component).isNotNull();
    Map<String, Object> map = Collections.singletonMap("value", "webController");
    MergedAnnotation<Component> annotation = MergedAnnotation.of(Component.class, map);
    Component synthesizedComponent = annotation.synthesize();
    assertThat(synthesizedComponent).isInstanceOf(SynthesizedAnnotation.class);
    assertThat(synthesizedComponent.value()).isEqualTo("webController");
}
Also used : Component(org.springframework.core.testfixture.stereotype.Component) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)12 Component (org.springframework.core.testfixture.stereotype.Component)12 AnnotationUtils.getAnnotationAttributes (org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes)2