Skip to content

Conversation

@Vampire
Copy link
Member

@Vampire Vampire commented Nov 14, 2025

Summary by CodeRabbit

  • New Features

    • Added Spring 7 test module support with Java 17 toolchain configuration and comprehensive test coverage for Spring framework integration.
  • Chores

    • Standardized Gradle dependency declaration syntax across Spring test modules for consistency.

✏️ Tip: You can customize this high-level summary in your review settings.

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

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.07%. Comparing base (158e2e4) to head (c616136).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #2262   +/-   ##
=========================================
  Coverage     82.07%   82.07%           
+ Complexity     4754     4753    -1     
=========================================
  Files           465      465           
  Lines         14872    14872           
  Branches       1877     1877           
=========================================
  Hits          12206    12206           
  Misses         1978     1978           
  Partials        688      688           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@@ -0,0 +1,34 @@
def springVersion = "7.0.0"
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be good to move the version into the libs.versions.toml, and use it there in a dependency, just do make it updateable via renovate, something like spring7Versionsimilar to junit?

testImplementation projects.spockSpring
testImplementation libs.junit4
testImplementation "org.springframework:spring-context"
testImplementation("org.springframework:spring-test")
Copy link
Member

Choose a reason for hiding this comment

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

To make is same as the other dependencies.

Suggested change
testImplementation("org.springframework:spring-test")
testImplementation "org.springframework:spring-test"


testImplementation projects.spockCore
testImplementation projects.spockSpring
testImplementation libs.junit4
Copy link
Member

@AndreasTu AndreasTu Nov 15, 2025

Choose a reason for hiding this comment

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

Why do you use Junit4 here?
Is it due to the SpringRunnerTest?

Copy link
Member Author

Choose a reason for hiding this comment

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

I have no idea. -:-D
I just copied the spring6 to spring7 and the boot3 to boot4, changed the packages and made the adjustments to make them run.
So everything you said in both PRs is probably valid (didn't look in detail yet) but also for the existing projects.

@AndreasTu
Copy link
Member

There is also the new version missing in spock-spring\spring.gradle, where there is a Set of versions to test.

@AndreasTu
Copy link
Member

AndreasTu commented Nov 15, 2025

When I execute gradlew :spock-spring:check locally with Java 21, it already fails for the task spring6Test, but it works with Java 17.

It seams that there is already a regression with Java 21 and spring 6:

org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type 'org.spockframework.spring.Service2' available: expected single matching bean but found 4: org.spockframework.spring.Service2#0,org.spockframework.spring.Service2#1,org.spockframework.spring.Service2#2,aName

https://ge.spockframework.org/s/f5cvzjnfzd3da

Note: I also needed to adapt the line in spring.gradle to "6.0.0": (17..21),

@coderabbitai
Copy link

coderabbitai bot commented Jan 4, 2026

📝 Walkthrough

Walkthrough

The changes introduce support for Spring 7 in the Spock framework by adding a new spring7-test module. Three existing Gradle build scripts receive syntax cleanup (removing parentheses from dependency declarations), and the new module includes its build configuration, test infrastructure classes, and multiple test cases validating Spring 7 compatibility with Spock tests.

Changes

Cohort / File(s) Summary
Gradle Syntax Cleanup
spock-spring/spring{3,5,6}-test/*.gradle
Minor syntax normalization: removed parentheses from testImplementation declarations across three Spring variant modules; no functional impact on dependency resolution
Spring 7 Module Enablement
settings.gradle
Added spock-spring:spring7-test to the non-2.5 variant inclusion block in settings
Spring 7 Build Configuration
spock-spring/spring7-test/spring7-test.gradle
New Gradle build file for spring7-test module: defines Spring 7.0.0 version, configures Java 17 toolchain with UTF-8 encoding, declares test and core dependencies (Spock, JUnit4, Spring modules), and enforces org.springframework version alignment
Spring 7 Test Infrastructure
spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/{NoMockConfig, TestConfig}.groovy
New Spring configuration classes: NoMockConfig defines ExecutorService and ServiceExecutor beans for testing; TestConfig provides a detached mock Executor bean using DetachedMockFactory
Spring 7 Compatibility Tests
spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/{RuntimeCompatibilitySpec, SpringBeanTest}.groovy, SpringRunnerTest.java
Three new test classes validating Spring 7 integration: RuntimeCompatibilitySpec tests Spring injection into Spock specs, SpringBeanTest tests bean mocking with Spock's @SpringBean, SpringRunnerTest validates non-Spock JUnit tests with SpringRunner

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~23 minutes

Poem

🐰 A springtime hop to version seven!
With Spock's own test suite climbing toward heaven,
New beans are wired, new mocks take flight,
Java 17 shines, the toolchain's right—
Spring 7 support, now fully grown.
Hop-hop! 🌱

Pre-merge checks and finishing touches

❌ 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%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ 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 spring7 tests' directly and clearly summarizes the main change: adding Spring 7 test support with multiple test configurations and test files for the spring7-test module.
✨ Finishing touches
  • 📝 Generate docstrings

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

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: 1

♻️ Duplicate comments (2)
spock-spring/spring7-test/spring7-test.gradle (2)

1-1: Consider moving version to libs.versions.toml for automated updates.

Hardcoding the Spring version here means Renovate/Dependabot won't automatically detect and propose updates. Moving it to libs.versions.toml (similar to other version declarations) would enable automated dependency management.


21-21: JUnit 4 dependency usage was questioned in prior review.

A previous reviewer asked why JUnit 4 is used here. This may be intentional if testing SpringRunner compatibility, but worth confirming if JUnit 5 (Jupiter) would be more appropriate for Spring 7.

🧹 Nitpick comments (2)
spock-spring/spring7-test/spring7-test.gradle (1)

3-14: Redundant toolchain configuration.

The java.toolchain block (lines 3-7) already configures Java 17. The tasks.withType(JavaCompile) block (lines 9-14) redundantly sets the same languageVersion. The encoding configuration is valid, but the compiler version is duplicative.

🔎 Suggested simplification
 java {
   toolchain {
     languageVersion = JavaLanguageVersion.of(17)
   }
 }

 tasks.withType(JavaCompile).configureEach {
-  javaCompiler = javaToolchains.compilerFor {
-    languageVersion = JavaLanguageVersion.of(17)
-  }
   options.encoding = 'UTF-8'
 }
spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/NoMockConfig.groovy (1)

9-10: Consider adding @Configuration annotation.

While Spring may detect the @Bean methods through component scanning or explicit @ContextConfiguration usage, adding the @Configuration annotation makes the intent explicit and is the conventional pattern.

🔎 Suggested fix
 import groovy.transform.CompileStatic
+import org.springframework.context.annotation.Configuration
 import org.springframework.context.annotation.Bean

 import java.util.concurrent.Callable
 import java.util.concurrent.ExecutorService

 @CompileStatic
+@Configuration
 class NoMockConfig {
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77d0adb and 1d7cf15.

📒 Files selected for processing (10)
  • settings.gradle
  • spock-spring/spring3-test/spring3-test.gradle
  • spock-spring/spring5-test/spring5-test.gradle
  • spock-spring/spring6-test/spring6-test.gradle
  • spock-spring/spring7-test/spring7-test.gradle
  • spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/NoMockConfig.groovy
  • spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/RuntimeCompatibilitySpec.groovy
  • spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/SpringBeanTest.groovy
  • spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/SpringRunnerTest.java
  • spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/TestConfig.groovy
🔇 Additional comments (10)
spock-spring/spring3-test/spring3-test.gradle (1)

8-8: LGTM!

The syntax change aligns with the other dependency declarations in the file, improving consistency.

spock-spring/spring5-test/spring5-test.gradle (1)

10-10: LGTM!

Consistent syntax style with other dependency declarations in this file.

spock-spring/spring6-test/spring6-test.gradle (1)

23-23: LGTM!

Syntax consistency with surrounding dependency declarations.

settings.gradle (1)

107-107: LGTM!

The new Spring 7 test module is correctly added in the non-2.5 variant block, maintaining logical version ordering after spring6-test.

Note: Based on PR comments, ensure that the new Spring version is also added to the set of versions to test in spock-spring/spring.gradle.

spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/TestConfig.groovy (1)

1-17: LGTM!

Clean Spring configuration using DetachedMockFactory to provide a stubbed Executor bean. The @CompileStatic annotation is a good practice for ensuring type safety.

spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/SpringRunnerTest.java (1)

16-19: LGTM!

The test serves its purpose of verifying that non-Spock tests using SpringJUnit4ClassRunner execute correctly within the Spring 7 module.

spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/SpringBeanTest.groovy (1)

1-30: LGTM!

Well-structured Spock specification demonstrating @SpringBean functionality with Spring 7. The test correctly:

  • Uses @ContextConfiguration with NoMockConfig as the base configuration
  • Replaces the ExecutorService bean with a mock via @SpringBean
  • Verifies both the mock interaction and return value
spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/RuntimeCompatibilitySpec.groovy (1)

1-24: LGTM!

The runtime compatibility spec is appropriately simple for its purpose—verifying that Spring 7 context loading and autowiring work correctly with Spock. The trivial 1 == 1 assertion in the first test is intentional: if the Spring context fails to load, the test will fail before reaching that line.

spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/NoMockConfig.groovy (1)

25-35: LGTM with minor note on consistency.

The ServiceExecutor class correctly models a service that depends on ExecutorService for the mock replacement test scenario. The exec() method using def return type is acceptable for test code, though an explicit String return type would be slightly more self-documenting.

spock-spring/spring7-test/spring7-test.gradle (1)

28-34: Spring 7 should be added to the test matrix in spock-spring/spring.gradle.

The current testSpringVersions map only includes Spring 4.3.5, 5.0.2, and 6.0.0. To ensure Spring 7 is tested alongside the other versions, add it to the testSpringVersions map with the appropriate Java version constraints (e.g., Java 17+).

Comment on lines +12 to +14
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class SpringRunnerTest {
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

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for any context configuration files related to SpringRunnerTest
fd -t f "SpringRunnerTest" spock-spring/spring7-test/

echo "---"
# Also search for any -context.xml files in spring7-test
fd -t f "\-context\.xml$" spock-spring/spring7-test/

echo "---"
# Check what files exist in the test directory structure
fd -t f "\.xml$|\.java$|\.groovy$" spock-spring/spring7-test/src/test | head -20

Repository: spockframework/spock

Length of output: 621


🏁 Script executed:

#!/bin/bash
# Read the SpringRunnerTest.java file to see full class content
cat -n spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/SpringRunnerTest.java

Repository: spockframework/spock

Length of output: 770


🏁 Script executed:

#!/bin/bash
# Check how other tests configure their Spring context
rg -A 3 "@ContextConfiguration|@SpringBootTest" spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/ -t groovy -t java

Repository: spockframework/spock

Length of output: 1482


🏁 Script executed:

#!/bin/bash
# Check if there's any base test class or configuration that SpringRunnerTest might inherit from
rg "class SpringRunnerTest|extends|@Configuration" spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/SpringRunnerTest.java -A 5 -B 5

Repository: spockframework/spock

Length of output: 367


Specify context configuration explicitly.

The @ContextConfiguration annotation has no classes or locations parameter, which is inconsistent with other test classes in the same directory and relies on Spring's default context discovery. Since this test doesn't use any Spring beans, either:

  • Remove @ContextConfiguration if no context is needed, or
  • Specify @ContextConfiguration(classes = {}) to explicitly define an empty context

This prevents reliance on Spring's implicit behavior which may vary across versions or configurations.

🤖 Prompt for AI Agents
In
spock-spring/spring7-test/src/test/groovy/org/spockframework/spring7/SpringRunnerTest.java
around lines 12 to 14, the @ContextConfiguration annotation is empty which
relies on Spring's default context discovery; since this test does not use any
Spring beans, either remove the @ContextConfiguration annotation entirely, or
make the configuration explicit by changing it to @ContextConfiguration(classes
= {}) so the test does not depend on implicit/version-dependent context
discovery.

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.

4 participants