1
1
/*
2
- * Copyright 2002-2012 the original author or authors.
2
+ * Copyright 2002-2013 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .context .annotation ;
18
18
19
- import example .scannable .DefaultNamedComponent ;
20
- import org .junit .Test ;
19
+ import java .lang .annotation .ElementType ;
20
+ import java .lang .annotation .Retention ;
21
+ import java .lang .annotation .RetentionPolicy ;
22
+ import java .lang .annotation .Target ;
21
23
24
+ import org .junit .Test ;
22
25
import org .springframework .beans .factory .annotation .AnnotatedBeanDefinition ;
23
26
import org .springframework .beans .factory .annotation .AnnotatedGenericBeanDefinition ;
24
27
import org .springframework .beans .factory .support .BeanDefinitionRegistry ;
25
28
import org .springframework .beans .factory .support .SimpleBeanDefinitionRegistry ;
26
29
import org .springframework .stereotype .Component ;
30
+ import org .springframework .stereotype .Service ;
27
31
import org .springframework .util .StringUtils ;
28
32
33
+ import example .scannable .DefaultNamedComponent ;
29
34
import static org .junit .Assert .*;
30
35
31
36
/**
@@ -81,6 +86,22 @@ public void testGenerateBeanNameWithAnonymousComponentYieldsGeneratedBeanName()
81
86
assertEquals (expectedGeneratedBeanName , beanName );
82
87
}
83
88
89
+ @ Test
90
+ public void testGenerateBeanNameFromMetaComponentWithStringValue () {
91
+ BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry ();
92
+ AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition (ComponentFromStringMeta .class );
93
+ String beanName = this .beanNameGenerator .generateBeanName (bd , registry );
94
+ assertEquals ("henry" , beanName );
95
+ }
96
+
97
+ @ Test
98
+ public void testGenerateBeanNameFromMetaComponentWithNonStringValue () {
99
+ BeanDefinitionRegistry registry = new SimpleBeanDefinitionRegistry ();
100
+ AnnotatedBeanDefinition bd = new AnnotatedGenericBeanDefinition (ComponentFromNonStringMeta .class );
101
+ String beanName = this .beanNameGenerator .generateBeanName (bd , registry );
102
+ assertEquals ("annotationBeanNameGeneratorTests.ComponentFromNonStringMeta" , beanName );
103
+ }
104
+
84
105
85
106
@ Component ("walden" )
86
107
private static class ComponentWithName {
@@ -96,4 +117,19 @@ private static class ComponentWithBlankName {
96
117
private static class AnonymousComponent {
97
118
}
98
119
120
+ @ Service ("henry" )
121
+ private static class ComponentFromStringMeta {
122
+ }
123
+
124
+ @ Retention (RetentionPolicy .RUNTIME )
125
+ @ Target (ElementType .TYPE )
126
+ @ Component
127
+ public @interface NonStringMetaComponent {
128
+ long value ();
129
+ }
130
+
131
+ @ NonStringMetaComponent (123 )
132
+ private static class ComponentFromNonStringMeta {
133
+ }
134
+
99
135
}
0 commit comments