Skip to content

Add boot4 tests#2261

Open
Vampire wants to merge 1 commit intomasterfrom
boot4-test
Open

Add boot4 tests#2261
Vampire wants to merge 1 commit intomasterfrom
boot4-test

Conversation

@Vampire
Copy link
Member

@Vampire Vampire commented Nov 14, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • Added Spring Boot 4 test module with sample applications demonstrating integration with Spring Data JPA, REST endpoints, and dependency injection patterns
    • Includes request-scoped bean examples and property-based configuration
  • Tests

    • Added comprehensive integration tests validating data layer operations, application context initialization, REST endpoint behavior, and scoped bean management

Copy link
Member Author

Vampire commented Nov 14, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codecov
Copy link

codecov bot commented Nov 14, 2025

Codecov Report

❌ Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.16%. Comparing base (9c6342c) to head (aa7c7ed).

Files with missing lines Patch % Lines
...n/java/org/spockframework/boot4/SimpleBootApp.java 60.00% 2 Missing ⚠️
...pockframework/boot4/service/HelloWorldService.java 50.00% 1 Missing ⚠️
...amework/boot4/service/ScopedHelloWorldService.java 50.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #2261      +/-   ##
============================================
- Coverage     82.16%   82.16%   -0.01%     
- Complexity     4822     4831       +9     
============================================
  Files           472      477       +5     
  Lines         15036    15054      +18     
  Branches       1905     1905              
============================================
+ Hits          12355    12369      +14     
- Misses         1989     1993       +4     
  Partials        692      692              
Files with missing lines Coverage Δ
...c/main/java/org/spockframework/boot4/jpa/Book.java 100.00% <100.00%> (ø)
...spockframework/boot4/web/HelloWorldController.java 100.00% <100.00%> (ø)
...pockframework/boot4/service/HelloWorldService.java 50.00% <50.00%> (ø)
...amework/boot4/service/ScopedHelloWorldService.java 50.00% <50.00%> (ø)
...n/java/org/spockframework/boot4/SimpleBootApp.java 60.00% <60.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

This PR adds a new boot4-test module to spock-spring, introducing a Spring Boot 4 test application with JPA entities, services, a web controller, configuration properties, and comprehensive Spock-based integration tests covering DataJpaTest, WebMvcTest, and scoped bean mocking patterns.

Changes

Cohort / File(s) Summary
Module Configuration
settings.gradle, spock-spring/boot4-test/boot4-test.gradle
Updated settings to include boot4-test module in non-2.5 variants; new Gradle build script configures Java 17 toolchain, applies Spring Boot and Groovy plugins, and defines dependencies for Spring Boot starters, Spock, and test integrations.
Application Components
spock-spring/boot4-test/src/main/java/org/spockframework/boot4/SimpleBootApp.java, spock-spring/boot4-test/src/main/java/org/spockframework/boot4/service/HelloWorldService.java, spock-spring/boot4-test/src/main/java/org/spockframework/boot4/service/ScopedHelloWorldService.java, spock-spring/boot4-test/src/main/java/org/spockframework/boot4/web/HelloWorldController.java
New Spring Boot application entry point, injectable services (standard and request-scoped), and REST controller with dependency injection via constructor.
JPA Layer
spock-spring/boot4-test/src/main/java/org/spockframework/boot4/jpa/Book.java, spock-spring/boot4-test/src/main/java/org/spockframework/boot4/jpa/BookRepository.java
JPA entity with auto-generated ID and title field; Spring Data CrudRepository interface for Book persistence operations.
Configuration
spock-spring/boot4-test/src/main/resources/application.properties
Spring Boot application properties: configurable name, disabled root logging, and Hibernate DDL auto-creation.
Integration Tests
spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/DataJpaTestIntegrationSpec.groovy, spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SimpleBootAppIntegrationSpec.groovy, spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBeanIntegrationSpec.groovy, spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationIntegrationSpec.groovy, spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedMockSpec.groovy, spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedProxyMockSpec.groovy, spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/WebMvcTestIntegrationSpec.groovy
Comprehensive Spock-based integration tests validating DataJpaTest slice (repository operations), full application context loading, WebMvcTest slice with mocked services, scoped bean handling, and detached/proxied mock factories in Spring Boot testing contexts.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested reviewers

  • AndreasTu

Poem

🐰 A boot4 module hops into view,
With services, beans, and tests so true,
JPA entities and scoped proxies dance,
Spock's magic gives integration a chance!
From repositories to controllers with flair,
Spring Boot testing blooms everywhere! 🌱

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add boot4 tests' directly summarizes the main change: introducing a new boot4-test module with comprehensive Spring Boot integration tests for Spock framework.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch boot4-test
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Vampire Vampire marked this pull request as ready for review March 13, 2026 04:13
@greptile-apps
Copy link

greptile-apps bot commented Mar 13, 2026

Greptile Summary

This PR adds a new boot4-test subproject to validate Spock's Spring integration against Spring Boot 4.x, following the same structural pattern already established by boot3-test. It registers the new subproject in settings.gradle (guarded by the existing Java 17 / non-Groovy-2.5 condition) and ports all seven test specs from boot3boot4, adapting imports and dependency declarations to Spring Boot 4's reorganized module layout.

Key changes:

  • New boot4-test.gradle adds Spring Boot 4.0.3 plugin and introduces two new test-slice starters absent from boot3: spring-boot-starter-data-jpa-test and spring-boot-starter-webmvc-test, reflecting Spring Boot 4's modular test-slice packaging.
  • All test specs are faithfully adapted; the only structural difference from their boot3 counterparts is updated import package paths (e.g. org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest instead of org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest).
  • DataJpaTestIntegrationSpec imports DataJpaTest from org.springframework.boot.data.jpa.test.autoconfigure but TestEntityManager from org.springframework.boot.jpa.test.autoconfigure — the differing package roots (data.jpa vs jpa) are worth double-checking against the actual Spring Boot 4 artifact layout to ensure neither import resolves incorrectly at compile time.

Confidence Score: 4/5

  • This PR is safe to merge; it adds new test infrastructure with no changes to production Spock code.
  • All changes are purely additive test/build files. The structure mirrors the well-established boot3-test subproject. The only item worth a closer look is the split package roots used for DataJpaTest and TestEntityManager in the JPA integration spec, which could fail at compile time if one package path is wrong — but this does not affect any existing functionality.
  • spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/DataJpaTestIntegrationSpec.groovy — verify the two different package roots for the JPA test imports.

Important Files Changed

Filename Overview
spock-spring/boot4-test/boot4-test.gradle Gradle build file for Spring Boot 4 integration tests; adds new Spring Boot 4-specific test starters (spring-boot-starter-data-jpa-test, spring-boot-starter-webmvc-test) not present in boot3-test.gradle, correctly targets Java 17 and uses Spring Boot 4.0.3.
spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/DataJpaTestIntegrationSpec.groovy Uses Spring Boot 4 package paths for DataJpaTest and TestEntityManager, but they come from inconsistent package roots (data.jpa vs jpa) — requires verification against actual Spring Boot 4 module layout.
spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBeanIntegrationSpec.groovy Correctly adapted from boot3; uses the new org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest package path for Spring Boot 4; logic is identical to the boot3 equivalent.
spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/WebMvcTestIntegrationSpec.groovy Correctly uses new org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest package for Spring Boot 4; otherwise identical structure to boot3's equivalent.
settings.gradle Correctly includes spock-spring:boot4-test inside the non-Groovy-2.5 guard block (alongside boot3-test and spring6-test), which enforces the Java 17 requirement.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    SG[settings.gradle - non-Groovy-2.5 block] --> B3[spock-spring:boot3-test]
    SG --> B4[spock-spring:boot4-test]
    SG --> S6[spock-spring:spring6-test]

    B4 --> GRADLE[boot4-test.gradle - Spring Boot 4.0.3]
    GRADLE --> DEPS[New test starters - data-jpa-test and webmvc-test]

    B4 --> MAIN[Main sources]
    MAIN --> M1[SimpleBootApp]
    MAIN --> M2[HelloWorldService]
    MAIN --> M3[ScopedHelloWorldService]
    MAIN --> M4[HelloWorldController]
    MAIN --> M5[Book and BookRepository]

    B4 --> TESTS[Test specs]
    TESTS --> T1[SimpleBootAppIntegrationSpec]
    TESTS --> T2[SpringBootTestAnnotationIntegrationSpec]
    TESTS --> T3[SpringBeanIntegrationSpec]
    TESTS --> T4[WebMvcTestIntegrationSpec]
    TESTS --> T5[DataJpaTestIntegrationSpec]
    TESTS --> T6[SpringBootTestAnnotationScopedMockSpec]
    TESTS --> T7[SpringBootTestAnnotationScopedProxyMockSpec]
Loading

Last reviewed commit: aa7c7ed

Comment on lines +24 to +25
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest
import org.springframework.boot.jpa.test.autoconfigure.TestEntityManager
Copy link

Choose a reason for hiding this comment

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

Inconsistent package roots for JPA test imports

DataJpaTest is imported from org.springframework.boot.data.jpa.test.autoconfigure while TestEntityManager is imported from org.springframework.boot.jpa.test.autoconfigure — note the difference: data.jpa vs jpa. This inconsistency in the package root is worth verifying against the actual Spring Boot 4 module layout. If both classes ship in the same artifact (spring-boot-starter-data-jpa-test), they are likely in the same or a closely related package tree, and one of these imports may be wrong. The boot3 analogue imported both from org.springframework.boot.test.autoconfigure.orm.jpa.* with a single wildcard import, which naturally avoided this kind of mismatch.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedProxyMockSpec.groovy (1)

52-55: Use Spring's proxy detection API instead of hard-coded internal bean names and generated class prefixes.

The scopedTarget.helloWorldService lookup and $$SpringCGLIB$$ class name prefix check depend on Spring Framework internals and generated class naming conventions. Spring provides standard testing utilities for this: AopUtils.isCglibProxy() to check proxy type semantically, and AopTestUtils.getTargetObject() to safely unwrap the target from the proxy. This pattern appears across the boot2, boot3, and boot4 test suites and should use the standard APIs instead.

Suggested change
-    def helloWorldServiceMock = context.getBean("scopedTarget.helloWorldService") as HelloWorldService
+    def helloWorldServiceMock = AopTestUtils.getTargetObject(helloWorldService)

     expect:
-    helloWorldService.class.simpleName.startsWith('HelloWorldService$$SpringCGLIB$$')
+    AopUtils.isCglibProxy(helloWorldService)

Add imports:

import org.springframework.aop.support.AopUtils
import org.springframework.test.util.AopTestUtils
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedProxyMockSpec.groovy`
around lines 52 - 55, Replace the brittle internal lookup and name-prefix
assertion by using Spring's proxy utilities: stop fetching the bean via
context.getBean("scopedTarget.helloWorldService") and stop asserting on
helloWorldService.class.simpleName; instead import and use
AopUtils.isCglibProxy(helloWorldService) to assert it's a CGLIB proxy and use
AopTestUtils.getTargetObject(helloWorldService) to obtain/unwrap the target for
any further assertions (update references to
helloWorldServiceMock/helloWorldService accordingly).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationIntegrationSpec.groovy`:
- Around line 31-32: The test enables bean definition overriding in the
`@SpringBootTest` annotation (in SpringBootTestAnnotationIntegrationSpec) by
setting the property 'spring.main.allow-bean-definition-overriding=true'; remove
that property from the annotation so the context fails fast on accidental
duplicate beans (i.e., edit the `@SpringBootTest`(...) on the class to drop the
properties array or remove that entry), then re-run the spec to ensure startup
still succeeds.

In
`@spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedMockSpec.groovy`:
- Around line 32-33: The test currently uses `@ScanScopedBeans` but tests a
singleton replacement bean (MockConfig.helloWorldService()), so it doesn't
actually verify scoped scanning; either change the replacement bean to a
non-singleton scope (e.g., annotate MockConfig.helloWorldService() as
`@Scope`("prototype") or use a scoped annotation used by
SpringMockTestExecutionListener) and update assertions to target that scoped
bean, or remove `@ScanScopedBeans` from the spec and rename the test class/methods
to indicate it's validating singleton/mock replacement behavior (adjust any
other occurrences at the same locations noted around lines 62-68 accordingly).

---

Nitpick comments:
In
`@spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedProxyMockSpec.groovy`:
- Around line 52-55: Replace the brittle internal lookup and name-prefix
assertion by using Spring's proxy utilities: stop fetching the bean via
context.getBean("scopedTarget.helloWorldService") and stop asserting on
helloWorldService.class.simpleName; instead import and use
AopUtils.isCglibProxy(helloWorldService) to assert it's a CGLIB proxy and use
AopTestUtils.getTargetObject(helloWorldService) to obtain/unwrap the target for
any further assertions (update references to
helloWorldServiceMock/helloWorldService accordingly).

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2a080b41-a247-4a01-aaae-43aa1a5f18bf

📥 Commits

Reviewing files that changed from the base of the PR and between 9c6342c and aa7c7ed.

📒 Files selected for processing (16)
  • settings.gradle
  • spock-spring/boot4-test/boot4-test.gradle
  • spock-spring/boot4-test/src/main/java/org/spockframework/boot4/SimpleBootApp.java
  • spock-spring/boot4-test/src/main/java/org/spockframework/boot4/jpa/Book.java
  • spock-spring/boot4-test/src/main/java/org/spockframework/boot4/jpa/BookRepository.java
  • spock-spring/boot4-test/src/main/java/org/spockframework/boot4/service/HelloWorldService.java
  • spock-spring/boot4-test/src/main/java/org/spockframework/boot4/service/ScopedHelloWorldService.java
  • spock-spring/boot4-test/src/main/java/org/spockframework/boot4/web/HelloWorldController.java
  • spock-spring/boot4-test/src/main/resources/application.properties
  • spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/DataJpaTestIntegrationSpec.groovy
  • spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SimpleBootAppIntegrationSpec.groovy
  • spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBeanIntegrationSpec.groovy
  • spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationIntegrationSpec.groovy
  • spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedMockSpec.groovy
  • spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedProxyMockSpec.groovy
  • spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/WebMvcTestIntegrationSpec.groovy

Comment on lines +31 to +32
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = ['spring.main.allow-bean-definition-overriding=true'])
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Drop bean overriding from this context-load spec.

Nothing in this spec replaces application beans, so enabling spring.main.allow-bean-definition-overriding only weakens the test: an accidental duplicate bean would be silently accepted instead of failing startup.

Suggested cleanup
-@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
-  properties = ['spring.main.allow-bean-definition-overriding=true'])
+@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE,
properties = ['spring.main.allow-bean-definition-overriding=true'])
`@SpringBootTest`(webEnvironment = SpringBootTest.WebEnvironment.NONE)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationIntegrationSpec.groovy`
around lines 31 - 32, The test enables bean definition overriding in the
`@SpringBootTest` annotation (in SpringBootTestAnnotationIntegrationSpec) by
setting the property 'spring.main.allow-bean-definition-overriding=true'; remove
that property from the annotation so the context fails fast on accidental
duplicate beans (i.e., edit the `@SpringBootTest`(...) on the class to drop the
properties array or remove that entry), then re-run the spec to ensure startup
still succeeds.

Comment on lines +32 to +33
@ScanScopedBeans
@SpringBootTest(properties = ['spring.main.allow-bean-definition-overriding=true'])
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

@ScanScopedBeans isn't actually under test here.

Per spock-spring/src/main/java/org/spockframework/spring/SpringMockTestExecutionListener.java:94-103, singleton bean definitions are attached even without @ScanScopedBeans; only non-singletons take the scoped-scan path. Since MockConfig.helloWorldService() is a plain singleton @Bean, this spec would still pass if scoped-bean scanning regressed.

Either make the replacement bean scoped or point the assertions at an actual scoped mock; otherwise this should drop @ScanScopedBeans and be renamed to reflect the non-scoped case.

Also applies to: 62-68

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@spock-spring/boot4-test/src/test/groovy/org/spockframework/boot4/SpringBootTestAnnotationScopedMockSpec.groovy`
around lines 32 - 33, The test currently uses `@ScanScopedBeans` but tests a
singleton replacement bean (MockConfig.helloWorldService()), so it doesn't
actually verify scoped scanning; either change the replacement bean to a
non-singleton scope (e.g., annotate MockConfig.helloWorldService() as
`@Scope`("prototype") or use a scoped annotation used by
SpringMockTestExecutionListener) and update assertions to target that scoped
bean, or remove `@ScanScopedBeans` from the spec and rename the test class/methods
to indicate it's validating singleton/mock replacement behavior (adjust any
other occurrences at the same locations noted around lines 62-68 accordingly).

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.

1 participant