Skip to content

Add self-reference to ApplicationContextAssertProvider - #50500

Closed
scordio wants to merge 1 commit into
spring-projects:mainfrom
scordio:ApplicationContextAssertProvider-generics
Closed

scordio wants to merge 1 commit into
spring-projects:mainfrom
scordio:ApplicationContextAssertProvider-generics

Conversation

@scordio

@scordio scordio commented May 25, 2026 •

Copy link
Copy Markdown
Contributor

Prior to this change, the following wouldn't compile:

new ApplicationContextRunner().run(context ->
  assertThat(context)            // returns ApplicationContextAssert<ConfigurableApplicationContext>
    .satisfies(
      ctx -> assertThat(ctx)     // returns ObjectAssert<ConfigurableApplicationContext>
        .hasNotFailed(),         // does not compile
      ctx -> assertThat(ctx)     // returns ObjectAssert<ConfigurableApplicationContext>
        .doesNotHaveBean("foo")) // does not compile
    );

This was due to ApplicationContextAssertProvider carrying ConfigurableApplicationContext as the type under assertion, which didn't play well with AssertJ methods like satisfies that allow nesting further assertions via given consumers.

Now ApplicationContextAssertProvider instances carry a self-reference, and assertions like satisfies can be chained correctly:

new ApplicationContextRunner().run(context ->
  assertThat(context)            // returns ApplicationContextAssert<AssertableApplicationContext>
    .satisfies(
      ctx -> assertThat(ctx)     // returns ApplicationContextAssert<AssertableApplicationContext>
        .hasNotFailed(),         // compiles!
      ctx -> assertThat(ctx)     // returns ApplicationContextAssert<AssertableApplicationContext>
        .doesNotHaveBean("foo")) // compiles!
    );

This is effectively a breaking change due to the additional type parameters of ApplicationContextAssertProvider. However, I imagine the change will be transparent to users who use the ApplicationContextRunner via its fluent API.

Relates to:

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. label May 25, 2026
@scordio
scordio marked this pull request as draft May 25, 2026 17:06
@scordio
scordio force-pushed the ApplicationContextAssertProvider-generics branch 2 times, most recently from 99d0045 to 1922982 Compare May 25, 2026 18:10
Signed-off-by: Stefano Cordio <stefano.cordio@gmail.com>
@scordio
scordio force-pushed the ApplicationContextAssertProvider-generics branch from 1922982 to 930980e Compare May 25, 2026 19:37
@scordio
scordio marked this pull request as ready for review May 25, 2026 19:37
@snicoll

snicoll commented May 26, 2026

Copy link
Copy Markdown
Member

Yeah I agree that would be more idiomatic indeed. However, this is a breaking change for anyone implementing the interface so I don't think we can merge this sooner than 4.2.x. Flagging to get more feedback from the team.

@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label May 26, 2026
@philwebb

Copy link
Copy Markdown
Member

My vote is to wait until 4.2.x at this point. It's a nice change, but I don't want to risk accidentally breaking things this late in the release cycle.

@snicoll snicoll added this to the 4.x milestone May 30, 2026
@snicoll snicoll added type: enhancement A general enhancement and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue that has not yet been triaged. Contributions will not be accepted. labels May 30, 2026
@wilkinsona wilkinsona modified the milestones: 4.x, 4.2.x Jun 28, 2026
@snicoll snicoll self-assigned this Jul 15, 2026
@snicoll snicoll modified the milestones: 4.2.x, 4.2.0-M1 Jul 15, 2026
@snicoll snicoll changed the title Add self reference to ApplicationContextAssertProvider Add self-reference to ApplicationContextAssertProvider Jul 15, 2026
snicoll pushed a commit that referenced this pull request Jul 15, 2026
See gh-50500

Signed-off-by: Stefano Cordio <stefano.cordio@gmail.com>
@snicoll snicoll closed this in d7a86df Jul 15, 2026
@scordio
scordio deleted the ApplicationContextAssertProvider-generics branch July 15, 2026 11:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants