Test status quo for @Components with multiple declared names
This commit is contained in:
@@ -36,6 +36,7 @@ import org.springframework.stereotype.Controller;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link AnnotationBeanNameGenerator}.
|
* Unit tests for {@link AnnotationBeanNameGenerator}.
|
||||||
@@ -70,6 +71,20 @@ class AnnotationBeanNameGeneratorTests {
|
|||||||
assertGeneratedNameIsDefault(ComponentWithBlankName.class);
|
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
|
@Test
|
||||||
void generateBeanNameWithJakartaNamedComponent() {
|
void generateBeanNameWithJakartaNamedComponent() {
|
||||||
assertGeneratedName(JakartaNamedComponent.class, "myJakartaNamedComponent");
|
assertGeneratedName(JakartaNamedComponent.class, "myJakartaNamedComponent");
|
||||||
@@ -144,6 +159,16 @@ class AnnotationBeanNameGeneratorTests {
|
|||||||
private static class ComponentWithBlankName {
|
private static class ComponentWithBlankName {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Component("myComponent")
|
||||||
|
@Service("myComponent")
|
||||||
|
static class ComponentWithDuplicateIdenticalNames {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Component("myComponent")
|
||||||
|
@Service("myService")
|
||||||
|
static class ComponentWithMultipleConflictingNames {
|
||||||
|
}
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
private static class AnonymousComponent {
|
private static class AnonymousComponent {
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user