Search in sources :

Example 6 with Component

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

the class MergedAnnotationsTests method synthesizeFromAnnotationAttributesWithoutAttributeAliases.

@Test
void synthesizeFromAnnotationAttributesWithoutAttributeAliases() throws Exception {
    Component component = WebController.class.getAnnotation(Component.class);
    assertThat(component).isNotNull();
    Map<String, Object> attributes = MergedAnnotation.from(component).asMap();
    Component synthesized = MergedAnnotation.of(Component.class, attributes).synthesize();
    assertThat(synthesized).isInstanceOf(SynthesizedAnnotation.class);
    assertThat(synthesized).isEqualTo(component);
}
Also used : Component(org.springframework.core.testfixture.stereotype.Component) Test(org.junit.jupiter.api.Test)

Example 7 with Component

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

the class MergedAnnotationsTests method synthesizeWithoutAttributeAliases.

@Test
void synthesizeWithoutAttributeAliases() throws Exception {
    Component component = WebController.class.getAnnotation(Component.class);
    assertThat(component).isNotNull();
    Component synthesizedComponent = MergedAnnotation.from(component).synthesize();
    assertThat(synthesizedComponent).isNotNull();
    assertThat(synthesizedComponent).isEqualTo(component);
    assertThat(synthesizedComponent.value()).isEqualTo("webController");
}
Also used : Component(org.springframework.core.testfixture.stereotype.Component) Test(org.junit.jupiter.api.Test)

Example 8 with Component

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

the class AnnotationUtilsTests method synthesizeAnnotationFromMapWithoutAttributeAliases.

@Test
void synthesizeAnnotationFromMapWithoutAttributeAliases() throws Exception {
    Component component = WebController.class.getAnnotation(Component.class);
    assertThat(component).isNotNull();
    Map<String, Object> map = Collections.singletonMap(VALUE, "webController");
    Component synthesizedComponent = synthesizeAnnotation(map, Component.class, WebController.class);
    assertThat(synthesizedComponent).isNotNull();
    assertThat(synthesizedComponent).isNotSameAs(component);
    assertThat(component.value()).as("value from component: ").isEqualTo("webController");
    assertThat(synthesizedComponent.value()).as("value from synthesized component: ").isEqualTo("webController");
}
Also used : Component(org.springframework.core.testfixture.stereotype.Component) Test(org.junit.jupiter.api.Test)

Example 9 with Component

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

the class AnnotationUtilsTests method findClassAnnotationOnMetaMetaAnnotatedClass.

@Test
void findClassAnnotationOnMetaMetaAnnotatedClass() {
    Component component = findAnnotation(MetaMetaAnnotatedClass.class, Component.class);
    assertThat(component).as("Should find 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 10 with Component

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

the class AnnotationUtilsTests method synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases.

@Test
void synthesizeAnnotationFromAnnotationAttributesWithoutAttributeAliases() throws Exception {
    // 1) Get an annotation
    Component component = WebController.class.getAnnotation(Component.class);
    assertThat(component).isNotNull();
    // 2) Convert the annotation into AnnotationAttributes
    AnnotationAttributes attributes = getAnnotationAttributes(WebController.class, component);
    assertThat(attributes).isNotNull();
    // 3) Synthesize the AnnotationAttributes back into an annotation
    Component synthesizedComponent = synthesizeAnnotation(attributes, Component.class, WebController.class);
    assertThat(synthesizedComponent).isNotNull();
    // 4) Verify that the original and synthesized annotations are equivalent
    assertThat(synthesizedComponent).isNotSameAs(component);
    assertThat(synthesizedComponent).isEqualTo(component);
    assertThat(component.value()).as("value from component: ").isEqualTo("webController");
    assertThat(synthesizedComponent.value()).as("value from synthesized component: ").isEqualTo("webController");
}
Also used : AnnotationUtils.getAnnotationAttributes(org.springframework.core.annotation.AnnotationUtils.getAnnotationAttributes) 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