26
26
import org .assertj .core .api .AbstractObjectArrayAssert ;
27
27
import org .assertj .core .api .AbstractObjectAssert ;
28
28
import org .assertj .core .api .AbstractThrowableAssert ;
29
- import org .assertj .core .api .Assertions ;
30
29
import org .assertj .core .api .MapAssert ;
31
30
import org .assertj .core .error .BasicErrorMessageFactory ;
32
31
import org .jspecify .annotations .Nullable ;
37
36
import org .springframework .boot .test .context .runner .ApplicationContextRunner ;
38
37
import org .springframework .context .ApplicationContext ;
39
38
import org .springframework .context .ConfigurableApplicationContext ;
39
+ import org .springframework .lang .CheckReturnValue ;
40
40
import org .springframework .util .Assert ;
41
41
42
42
import static org .assertj .core .api .Assertions .assertThat ;
@@ -224,13 +224,14 @@ public ApplicationContextAssert<C> doesNotHaveBean(String name) {
224
224
* @return array assertions for the bean names
225
225
* @throws AssertionError if the application context did not start
226
226
*/
227
+ @ CheckReturnValue
227
228
public <T > AbstractObjectArrayAssert <?, String > getBeanNames (Class <T > type ) {
228
229
if (this .startupFailure != null ) {
229
230
throwAssertionError (contextFailedToStartWhenExpecting (this .startupFailure ,
230
231
"to get beans names with type:%n <%s>" , type ));
231
232
}
232
- return Assertions . assertThat (getApplicationContext ().getBeanNamesForType (type ))
233
- . as ( "Bean names of type <%s> from <%s>" , type , getApplicationContext ());
233
+ return assertThat (getApplicationContext ().getBeanNamesForType (type )). as ( "Bean names of type <%s> from <%s>" ,
234
+ type , getApplicationContext ());
234
235
}
235
236
236
237
/**
@@ -249,6 +250,7 @@ public <T> AbstractObjectArrayAssert<?, String> getBeanNames(Class<T> type) {
249
250
* @throws AssertionError if the application context contains multiple beans of the
250
251
* given type
251
252
*/
253
+ @ CheckReturnValue
252
254
public <T > AbstractObjectAssert <?, T > getBean (Class <T > type ) {
253
255
return getBean (type , Scope .INCLUDE_ANCESTORS );
254
256
}
@@ -270,6 +272,7 @@ public <T> AbstractObjectAssert<?, T> getBean(Class<T> type) {
270
272
* @throws AssertionError if the application context contains multiple beans of the
271
273
* given type
272
274
*/
275
+ @ CheckReturnValue
273
276
public <T > AbstractObjectAssert <?, T > getBean (Class <T > type , Scope scope ) {
274
277
Assert .notNull (scope , "'scope' must not be null" );
275
278
if (this .startupFailure != null ) {
@@ -284,7 +287,7 @@ public <T> AbstractObjectAssert<?, T> getBean(Class<T> type, Scope scope) {
284
287
getApplicationContext (), type , names ));
285
288
}
286
289
T bean = (name != null ) ? getApplicationContext ().getBean (name , type ) : null ;
287
- return Assertions . assertThat (bean ).as ("Bean of type <%s> from <%s>" , type , getApplicationContext ());
290
+ return assertThat (bean ).as ("Bean of type <%s> from <%s>" , type , getApplicationContext ());
288
291
}
289
292
290
293
private @ Nullable String getPrimary (String [] names , Scope scope ) {
@@ -330,13 +333,14 @@ private boolean isPrimary(String name, Scope scope) {
330
333
* is found
331
334
* @throws AssertionError if the application context did not start
332
335
*/
336
+ @ CheckReturnValue
333
337
public AbstractObjectAssert <?, Object > getBean (String name ) {
334
338
if (this .startupFailure != null ) {
335
339
throwAssertionError (
336
340
contextFailedToStartWhenExpecting (this .startupFailure , "to contain a bean of name:%n <%s>" , name ));
337
341
}
338
342
Object bean = findBean (name );
339
- return Assertions . assertThat (bean ).as ("Bean of name <%s> from <%s>" , name , getApplicationContext ());
343
+ return assertThat (bean ).as ("Bean of name <%s> from <%s>" , name , getApplicationContext ());
340
344
}
341
345
342
346
/**
@@ -357,6 +361,7 @@ public AbstractObjectAssert<?, Object> getBean(String name) {
357
361
* name but a different type
358
362
*/
359
363
@ SuppressWarnings ("unchecked" )
364
+ @ CheckReturnValue
360
365
public <T > AbstractObjectAssert <?, T > getBean (String name , Class <T > type ) {
361
366
if (this .startupFailure != null ) {
362
367
throwAssertionError (contextFailedToStartWhenExpecting (this .startupFailure ,
@@ -368,8 +373,8 @@ public <T> AbstractObjectAssert<?, T> getBean(String name, Class<T> type) {
368
373
"%nExpecting:%n <%s>%nto contain a bean of name:%n <%s> (%s)%nbut found:%n <%s> of type <%s>" ,
369
374
getApplicationContext (), name , type , bean , bean .getClass ()));
370
375
}
371
- return Assertions . assertThat ((T ) bean )
372
- . as ( "Bean of name <%s> and type <%s> from <%s>" , name , type , getApplicationContext ());
376
+ return assertThat ((T ) bean ). as ( "Bean of name <%s> and type <%s> from <%s>" , name , type ,
377
+ getApplicationContext ());
373
378
}
374
379
375
380
private @ Nullable Object findBean (String name ) {
@@ -395,6 +400,7 @@ public <T> AbstractObjectAssert<?, T> getBean(String name, Class<T> type) {
395
400
* no beans are found
396
401
* @throws AssertionError if the application context did not start
397
402
*/
403
+ @ CheckReturnValue
398
404
public <T > MapAssert <String , T > getBeans (Class <T > type ) {
399
405
return getBeans (type , Scope .INCLUDE_ANCESTORS );
400
406
}
@@ -414,14 +420,15 @@ public <T> MapAssert<String, T> getBeans(Class<T> type) {
414
420
* no beans are found
415
421
* @throws AssertionError if the application context did not start
416
422
*/
423
+ @ CheckReturnValue
417
424
public <T > MapAssert <String , T > getBeans (Class <T > type , Scope scope ) {
418
425
Assert .notNull (scope , "'scope' must not be null" );
419
426
if (this .startupFailure != null ) {
420
427
throwAssertionError (
421
428
contextFailedToStartWhenExpecting (this .startupFailure , "to get beans of type:%n <%s>" , type ));
422
429
}
423
- return Assertions . assertThat (scope .getBeansOfType (getApplicationContext (), type ))
424
- . as ( "Beans of type <%s> from <%s>" , type , getApplicationContext ());
430
+ return assertThat (scope .getBeansOfType (getApplicationContext (), type )). as ( "Beans of type <%s> from <%s>" , type ,
431
+ getApplicationContext ());
425
432
}
426
433
427
434
/**
@@ -434,6 +441,7 @@ public <T> MapAssert<String, T> getBeans(Class<T> type, Scope scope) {
434
441
* @return assertions on the cause of the failure
435
442
* @throws AssertionError if the application context started without a failure
436
443
*/
444
+ @ CheckReturnValue
437
445
public AbstractThrowableAssert <?, ? extends Throwable > getFailure () {
438
446
hasFailed ();
439
447
return assertThat (this .startupFailure );
0 commit comments