I suggest to decorate ApplicationContextAssert::getBean(s) methods with a @CheckReturnValue annotation so that incomplete statements like the following are spotted by static analysis tools like SpotBugs and IntelliJ IDEA:

assertThat(context).getBean(MyService.class);

To achieve this, no additional dependency is needed and Spring Boot Test can declare its own @CheckReturnValue annotation, similarly to what AssertJ and Mockito do.

I can raise a PR with the changes if the idea is accepted.

Comment From: scordio

To achieve this, no additional dependency is needed and Spring Boot Test can declare its own @CheckReturnValue annotation, similarly to what AssertJ and Mockito do.

On second thought, Spring Boot Test might use org.assertj.core.util.CheckReturnValue directly since ApplicationContextAssert is an AssertJ-based implementation anyway.

Comment From: wilkinsona

Thanks for the suggestion, @scordio. Using @CheckReturnValue sounds like a good option in this particular case. However, I wonder if we have other APIs where a similar annotation would be beneficial. A bit like nullability annotations for Kotlin, handling this inconsistently may create more problems than it solves. Flagging for team attention to see what everyone else thinks.

Comment From: mhalbritter

I think this is a good idea if we do this consistently.

Comment From: philwebb

I like the idea as well and error prone has been on the list of things to investigate for a while.

Comment From: sdeleuze

This could be connected to https://github.com/spring-projects/spring-framework/issues/28797 (tentatively planned for 6.1) if we extends its scope via https://github.com/jspecify/jspecify/issues/200.

Comment From: sbrannen

Regarding Eclipse IDE support, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=572496.

Comment From: philwebb

Marking this as blocked as we want to see what Framework do.

Comment From: rstoyanchev

We are adding @CheckReturnValue to spring-core for 6.2, see https://github.com/spring-projects/spring-framework/issues/33818.