22
22
23
23
import org .junit .jupiter .api .Test ;
24
24
25
- import org .springframework .context .annotation .Bean ;
26
25
import org .springframework .core .annotation .AnnotationUtils ;
27
26
import org .springframework .lang .NonNull ;
28
27
import org .springframework .test .context .bean .override .convention .TestBeanOverrideProcessor .TestBeanOverrideMetadata ;
29
28
import org .springframework .test .context .bean .override .example .ExampleService ;
30
- import org .springframework .test .context .bean .override .example .FailingExampleService ;
31
29
32
30
import static org .assertj .core .api .Assertions .assertThat ;
33
31
import static org .assertj .core .api .Assertions .assertThatIllegalArgumentException ;
@@ -45,7 +43,7 @@ class TestBeanOverrideProcessorTests {
45
43
46
44
@ Test
47
45
void findTestBeanFactoryMethodFindsFromCandidateNames () {
48
- Class <?> clazz = MethodConventionConf .class ;
46
+ Class <?> clazz = MethodConventionTestCase .class ;
49
47
Class <?> returnType = ExampleService .class ;
50
48
51
49
Method method = findTestBeanFactoryMethod (clazz , returnType , "example1" , "example2" , "example3" );
@@ -55,7 +53,7 @@ void findTestBeanFactoryMethodFindsFromCandidateNames() {
55
53
56
54
@ Test
57
55
void findTestBeanFactoryMethodNotFound () {
58
- Class <?> clazz = MethodConventionConf .class ;
56
+ Class <?> clazz = MethodConventionTestCase .class ;
59
57
Class <?> returnType = ExampleService .class ;
60
58
61
59
assertThatIllegalStateException ()
@@ -68,7 +66,7 @@ void findTestBeanFactoryMethodNotFound() {
68
66
69
67
@ Test
70
68
void findTestBeanFactoryMethodTwoFound () {
71
- Class <?> clazz = MethodConventionConf .class ;
69
+ Class <?> clazz = MethodConventionTestCase .class ;
72
70
Class <?> returnType = ExampleService .class ;
73
71
74
72
assertThatIllegalStateException ()
@@ -82,13 +80,13 @@ void findTestBeanFactoryMethodTwoFound() {
82
80
@ Test
83
81
void findTestBeanFactoryMethodNoNameProvided () {
84
82
assertThatIllegalArgumentException ()
85
- .isThrownBy (() -> findTestBeanFactoryMethod (MethodConventionConf .class , ExampleService .class ))
83
+ .isThrownBy (() -> findTestBeanFactoryMethod (MethodConventionTestCase .class , ExampleService .class ))
86
84
.withMessage ("At least one candidate method name is required" );
87
85
}
88
86
89
87
@ Test
90
88
void createMetaDataForUnknownExplicitMethod () throws Exception {
91
- Class <?> clazz = ExplicitMethodNameConf .class ;
89
+ Class <?> clazz = ExplicitMethodNameTestCase .class ;
92
90
Class <?> returnType = ExampleService .class ;
93
91
Field field = clazz .getField ("a" );
94
92
TestBean overrideAnnotation = field .getAnnotation (TestBean .class );
@@ -105,7 +103,7 @@ void createMetaDataForUnknownExplicitMethod() throws Exception {
105
103
106
104
@ Test
107
105
void createMetaDataForKnownExplicitMethod () throws Exception {
108
- Class <?> clazz = ExplicitMethodNameConf .class ;
106
+ Class <?> clazz = ExplicitMethodNameTestCase .class ;
109
107
Field field = clazz .getField ("b" );
110
108
TestBean overrideAnnotation = field .getAnnotation (TestBean .class );
111
109
assertThat (overrideAnnotation ).isNotNull ();
@@ -118,7 +116,7 @@ void createMetaDataForKnownExplicitMethod() throws Exception {
118
116
@ Test
119
117
void createMetaDataForConventionBasedFactoryMethod () throws Exception {
120
118
Class <?> returnType = ExampleService .class ;
121
- Class <?> clazz = MethodConventionConf .class ;
119
+ Class <?> clazz = MethodConventionTestCase .class ;
122
120
Field field = clazz .getField ("field" );
123
121
TestBean overrideAnnotation = field .getAnnotation (TestBean .class );
124
122
assertThat (overrideAnnotation ).isNotNull ();
@@ -134,7 +132,7 @@ void createMetaDataForConventionBasedFactoryMethod() throws Exception {
134
132
135
133
@ Test
136
134
void failToCreateMetadataForOtherAnnotation () throws NoSuchFieldException {
137
- Class <?> clazz = MethodConventionConf .class ;
135
+ Class <?> clazz = MethodConventionTestCase .class ;
138
136
Field field = clazz .getField ("field" );
139
137
NonNull badAnnotation = AnnotationUtils .synthesizeAnnotation (NonNull .class );
140
138
@@ -145,26 +143,25 @@ void failToCreateMetadataForOtherAnnotation() throws NoSuchFieldException {
145
143
}
146
144
147
145
148
- static class MethodConventionConf {
146
+ static class MethodConventionTestCase {
149
147
150
148
@ TestBean (name = "someField" )
151
149
public ExampleService field ;
152
150
153
- @ Bean
154
151
ExampleService example1 () {
155
- return new FailingExampleService () ;
152
+ return null ;
156
153
}
157
154
158
155
static ExampleService example2 () {
159
- return new FailingExampleService () ;
156
+ return null ;
160
157
}
161
158
162
- public static ExampleService example4 () {
163
- return new FailingExampleService () ;
159
+ static ExampleService example4 () {
160
+ return null ;
164
161
}
165
162
}
166
163
167
- static class ExplicitMethodNameConf {
164
+ static class ExplicitMethodNameTestCase {
168
165
169
166
@ TestBean (methodName = "explicit1" )
170
167
public ExampleService a ;
@@ -173,7 +170,7 @@ static class ExplicitMethodNameConf {
173
170
public ExampleService b ;
174
171
175
172
static ExampleService explicit2 () {
176
- return new FailingExampleService () ;
173
+ return null ;
177
174
}
178
175
}
179
176
0 commit comments