Skip to content

Chore: Migrate testing infrastructure and SpEL evaluation to Spring Boot 4.0 / Spring 7#4318

Open
prathmeshcc wants to merge 6 commits intoGoogleCloudPlatform:8.0-migrationfrom
prathmeshcc:8.x-unit-tests
Open

Chore: Migrate testing infrastructure and SpEL evaluation to Spring Boot 4.0 / Spring 7#4318
prathmeshcc wants to merge 6 commits intoGoogleCloudPlatform:8.0-migrationfrom
prathmeshcc:8.x-unit-tests

Conversation

@prathmeshcc
Copy link

This PR contains the unit test fixes required for the Spring Boot 4.0 and Spring Framework 7 migration. These changes ensure that the test suite is compatible with the new modular architecture of Spring Boot 4, the upgraded Jakarta EE 11 baseline, and the refactored SpEL evaluation engine in Spring Data 4 (2025.1).

  1. Mockito Infrastructure (Spring Test 7.0)
  • Annotation Migration: Replaced @MockBean and @SpyBean (deprecated in Boot 4.0) with @MockitoBean and @MockitoSpyBean from the new org.springframework.test.context.bean.override.mockito package.
  • Explicit Test Configuration: Added @AutoConfigureMockMvc and @AutoConfigureTestRestTemplate to integration tests. Spring Boot 4.0 no longer provides these beans implicitly with @SpringBootTest, favoring explicit opt-in for better modularity and performance.
  1. Spring Data 4 / SpEL Evaluation
  • ValueExpressionDelegate: Migrated repository query tests from QueryMethodEvaluationContextProvider (removed in Spring Data 4) to ValueExpressionDelegate. This aligns with the new centralized "Value Expression" infrastructure for SpEL resolution.
  • Standardized Mapping Exceptions: Updated Spanner and Datastore metadata tests to handle the new exception hierarchy where module-specific errors (e.g., SpannerDataException) are now wrapped in a top-level org.springframework.data.mapping.MappingException.
  1. Spring Boot 4.0 Actuator & Health API
  • Restructured Health API: Updated tests to use the new org.springframework.boot.health.contributor package.
  • Composite Contributors: Refactored Health Indicator tests to correctly handle CompositeHealthContributor types, ensuring tests pass when indicators are grouped by the framework.
  1. Dependency & Package Updates
  • Jakarta EE 11: Migrated javax.annotation imports to jakarta.annotation.
  • Jackson 3: Updated Jackson imports to the new tools.jackson namespace as required by the Spring Boot 4 baseline.
  • Modular Dependencies: Added spring-boot-resttestclient and other granular test starters to module POMs to support the new modular testing architecture.

Verification Results

  • All unit tests passed locally via ./mvnw test -DskipITs -Dcheckstyle.skip -Dfmt.skip
  • Verified that all deprecated Mockito annotations have been removed.
  • Confirmed that EnvironmentPostProcessor registrations in spring.factories use the new Spring Boot 4 package paths.

- Upgrade Spring Boot to 4.0.0 and Spring Cloud to 2025.1.0
- Update documentation and remove legacy .jdk8 markers
- Replace deprecated @MockBean/@SpyBean with @MockitoBean/@MockitoSpyBean.
- Explicitly add @AutoConfigureMockMvc and @AutoConfigureTestRestTemplate to web tests.
- Update SpEL evaluation to use ValueExpressionDelegate and ValueEvaluationContext.
- Update Health Indicator tests to reflect Actuator package and API restructuring.
- Handle MappingException wrapping for Spanner/Datastore metadata tests.
- Update TestRestTemplate and Jakarta annotation imports to new baseline packages.
- Add necessary test-scoped dependencies for modular Spring Boot 4 testing.
@prathmeshcc prathmeshcc requested review from a team as code owners February 12, 2026 16:08
"The primary key columns were not given a consecutive order. There is no property annotated with order 2 in EntityWithWronglyOrderedKeys.");
}

private void assertThatMappingExceptionCause(Runnable runnable, String expectedMessage) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Spring Data 4.0 (part of the 2025.1 release train), the MappingContext has been updated to provide a more consistent error-handling contract across all modules. Metadata discovery and entity mapping failures are now uniformly wrapped in a top-level org.springframework.data.mapping.MappingException. This change ensures our tests accurately reflect this new exception hierarchy by asserting that our domain-specific SpannerDataException is preserved as the underlying cause of the framework's mapping failure.
Ref: Spring Data 4 Migration Guide

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the release notes, we should just mention that all MappingContext functions will have any exceptions wrapped in MappingContextException. If you were relying on specific root cause messages, you should update your code to use t.getCause().getMessage() to retrieve the specific error mesage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to use NestedExceptionUtils.getMostSpecificCause() here?

Copy link
Contributor

@ldetmer ldetmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good, just had a few clarifications

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this also be reverted since we reverted this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Contributor

@ldetmer ldetmer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you just check the one comment i made?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments