Test status quo for @Components with multiple declared names

This commit is contained in:
Sam Brannen
2023-08-23 16:00:41 +02:00
parent 71ba7bc5e0
commit aaa0a2be63

View File

@@ -36,6 +36,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
/**
* Unit tests for {@link AnnotationBeanNameGenerator}.
@@ -70,6 +71,20 @@ class AnnotationBeanNameGeneratorTests {
assertGeneratedNameIsDefault(ComponentWithBlankName.class);
}
@Test
void generateBeanNameForComponentWithDuplicateIdenticalNames() {
assertGeneratedName(ComponentWithDuplicateIdenticalNames.class, "myComponent");
}
@Test
void generateBeanNameForComponentWithConflictingNames() {
BeanDefinition bd = annotatedBeanDef(ComponentWithMultipleConflictingNames.class);
assertThatIllegalStateException()
.isThrownBy(() -> generateBeanName(bd))
.withMessage("Stereotype annotations suggest inconsistent component names: '%s' versus '%s'",
"myComponent", "myService");
}
@Test
void generateBeanNameWithJakartaNamedComponent() {
assertGeneratedName(JakartaNamedComponent.class, "myJakartaNamedComponent");
@@ -144,6 +159,16 @@ class AnnotationBeanNameGeneratorTests {
private static class ComponentWithBlankName {
}
@Component("myComponent")
@Service("myComponent")
static class ComponentWithDuplicateIdenticalNames {
}
@Component("myComponent")
@Service("myService")
static class ComponentWithMultipleConflictingNames {
}
@Component
private static class AnonymousComponent {
}