Commit 9181cce
committed
Support @MockitoBean at the type level on test classes
Prior to this commit, @MockitoBean could only be declared on fields
within test classes, which prevented developers from being able to
easily reuse mock configuration across a test suite.
With this commit, @MockitoBean is now supported at the type level on
test classes, their superclasses, and interfaces implemented by those
classes. @MockitoBean is also supported on enclosing classes for
@Nested test classes, their superclasses, and interfaces implemented
by those classes, while honoring @NestedTestConfiguration semantics.
In addition, @MockitoBean:
- has a new `types` attribute that can be used to declare the type or
types to mock when @MockitoBean is declared at the type level
- can be declared as a repeatable annotation at the type level
- can be declared as a meta-annotation on a custom composed annotation
which can be reused across a test suite (see the @SharedMocks
example in the reference manual)
To support these new features, this commit also includes the following
changes.
- The `field` property in BeanOverrideHandler is now @Nullable.
- BeanOverrideProcessor has a new `default` createHandlers() method
which is invoked when a @BeanOverride annotation is found at the
type level.
- MockitoBeanOverrideProcessor implements the new createHandlers()
method.
- The internal findHandlers() method in BeanOverrideHandler has been
completely overhauled.
- The @MockitoBean and @MockitoSpyBean section of the reference
manual has been completely overhauled.
Closes gh-339251 parent 8b6523a commit 9181cce
File tree
36 files changed
+1379
-144
lines changed- framework-docs/modules/ROOT/pages/testing/annotations/integration-spring
- spring-test/src
- main/java/org/springframework/test/context/bean/override
- mockito
- test/java/org/springframework/test/context/bean/override
- mockito
- mockbeans
36 files changed
+1379
-144
lines changedLines changed: 115 additions & 27 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 14 | | |
23 | 15 | | |
24 | 16 | | |
25 | 17 | | |
26 | | - | |
| 18 | + | |
27 | 19 | | |
28 | 20 | | |
29 | 21 | | |
30 | | - | |
| 22 | + | |
31 | 23 | | |
32 | | - | |
| 24 | + | |
33 | 25 | | |
34 | | - | |
35 | | - | |
36 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
37 | 29 | | |
38 | 30 | | |
39 | 31 | | |
| |||
61 | 53 | | |
62 | 54 | | |
63 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
64 | 67 | | |
65 | 68 | | |
66 | 69 | | |
| |||
69 | 72 | | |
70 | 73 | | |
71 | 74 | | |
72 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
76 | | - | |
| 81 | + | |
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| |||
82 | 87 | | |
83 | 88 | | |
84 | 89 | | |
85 | | - | |
86 | | - | |
| 90 | + | |
| 91 | + | |
87 | 92 | | |
88 | 93 | | |
89 | 94 | | |
| |||
93 | 98 | | |
94 | 99 | | |
95 | 100 | | |
96 | | - | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
97 | 104 | | |
98 | 105 | | |
99 | 106 | | |
100 | | - | |
| 107 | + | |
101 | 108 | | |
102 | 109 | | |
103 | 110 | | |
104 | 111 | | |
105 | 112 | | |
106 | 113 | | |
107 | | - | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
108 | 122 | | |
109 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
110 | 138 | | |
111 | 139 | | |
112 | 140 | | |
113 | 141 | | |
114 | 142 | | |
115 | 143 | | |
116 | 144 | | |
117 | | - | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
118 | 205 | | |
119 | 206 | | |
120 | 207 | | |
121 | | - | |
| 208 | + | |
122 | 209 | | |
123 | 210 | | |
124 | 211 | | |
| |||
137 | 224 | | |
138 | 225 | | |
139 | 226 | | |
140 | | - | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
141 | 230 | | |
142 | 231 | | |
143 | 232 | | |
144 | | - | |
145 | | - | |
| 233 | + | |
146 | 234 | | |
147 | 235 | | |
148 | 236 | | |
| |||
Lines changed: 8 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
28 | | - | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
33 | | - | |
34 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | | - | |
| 40 | + | |
37 | 41 | | |
38 | 42 | | |
39 | 43 | | |
| |||
Lines changed: 39 additions & 31 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
| 2 | + | |
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| |||
104 | 104 | | |
105 | 105 | | |
106 | 106 | | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
112 | 111 | | |
113 | 112 | | |
114 | 113 | | |
| |||
134 | 133 | | |
135 | 134 | | |
136 | 135 | | |
137 | | - | |
138 | 136 | | |
139 | 137 | | |
140 | 138 | | |
| |||
169 | 167 | | |
170 | 168 | | |
171 | 169 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
177 | 174 | | |
178 | 175 | | |
179 | 176 | | |
| |||
264 | 261 | | |
265 | 262 | | |
266 | 263 | | |
267 | | - | |
268 | | - | |
| 264 | + | |
269 | 265 | | |
270 | 266 | | |
271 | | - | |
272 | | - | |
273 | | - | |
| 267 | + | |
| 268 | + | |
274 | 269 | | |
275 | 270 | | |
276 | 271 | | |
| |||
281 | 276 | | |
282 | 277 | | |
283 | 278 | | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
289 | 282 | | |
290 | 283 | | |
291 | 284 | | |
| |||
308 | 301 | | |
309 | 302 | | |
310 | 303 | | |
311 | | - | |
312 | | - | |
| 304 | + | |
| 305 | + | |
313 | 306 | | |
314 | 307 | | |
315 | 308 | | |
| |||
320 | 313 | | |
321 | 314 | | |
322 | 315 | | |
323 | | - | |
324 | | - | |
325 | | - | |
| 316 | + | |
| 317 | + | |
326 | 318 | | |
327 | 319 | | |
328 | 320 | | |
329 | 321 | | |
330 | 322 | | |
| 323 | + | |
331 | 324 | | |
332 | 325 | | |
333 | 326 | | |
| |||
345 | 338 | | |
346 | 339 | | |
347 | 340 | | |
348 | | - | |
349 | | - | |
| 341 | + | |
| 342 | + | |
350 | 343 | | |
351 | 344 | | |
352 | 345 | | |
353 | 346 | | |
354 | 347 | | |
355 | 348 | | |
356 | | - | |
357 | | - | |
| 349 | + | |
| 350 | + | |
358 | 351 | | |
359 | 352 | | |
360 | 353 | | |
| |||
452 | 445 | | |
453 | 446 | | |
454 | 447 | | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
455 | 463 | | |
0 commit comments