|
|
|
|
@ -36,6 +36,7 @@ import org.springframework.stereotype.Controller;
@@ -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 {
@@ -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 {
@@ -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 { |
|
|
|
|
} |
|
|
|
|
|