Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ if (variant == 2.5) {
// require Java 17 which isn't supported by Groovy 2.5
include "spock-spring:boot3-test"
include "spock-spring:spring6-test"
include "spock-spring:spring7-test"
}

// https://issues.apache.org/jira/projects/TAP5/issues/TAP5-2588
Expand Down
34 changes: 34 additions & 0 deletions spock-spring/spring7-test/spring7-test.gradle
Original file line number Diff line number Diff line change
@@ -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?


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

tasks.withType(JavaCompile).configureEach {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(17)
}
options.encoding = 'UTF-8'
}

dependencies {
implementation "org.springframework:spring-core"

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.

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"


}


configurations.all {
resolutionStrategy.eachDependency {
if (requested.group == "org.springframework" ) {
useVersion(springVersion)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.spockframework.spring7

import groovy.transform.CompileStatic
import org.springframework.context.annotation.Bean

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

@CompileStatic
class NoMockConfig {

@Bean
ExecutorService executor() {
throw new RuntimeException("This should not be called")
}

@Bean
ServiceExecutor serviceExecutor(ExecutorService executorService) {
return new ServiceExecutor(executorService)
}


}

class ServiceExecutor {
private final ExecutorService executorService

ServiceExecutor(ExecutorService executorService) {
this.executorService = executorService
}

def exec() {
executorService.submit({"done"} as Callable).get()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.spockframework.spring7

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification

import java.util.concurrent.Executor

@ContextConfiguration(classes = TestConfig)
class RuntimeCompatibilitySpec extends Specification {

@Autowired
Executor injectMe

def "no runtime errors are thrown"() {
expect:
1 == 1
}

def "injection works"() {
expect:
injectMe != null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.spockframework.spring7

import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import spock.lang.Specification

import java.util.concurrent.ExecutorService
import java.util.concurrent.Future

@ContextConfiguration(classes = NoMockConfig)
class SpringBeanTest extends Specification {

@Autowired
ServiceExecutor serviceExecutor

@SpringBean
ExecutorService executor = Mock()

def "replace executor"() {
when:
def result = serviceExecutor.exec()

then:
result == 'mocked'
1 * executor.submit(_) >> Stub(Future) {
get() >> 'mocked'
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.spockframework.spring7;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

/**
* Make sure we still can correctly execute tests executed by the SpringRunner that are not spock tests
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class SpringRunnerTest {

@Test
public void testThatSpringRunnerExecutesCorrectly() {
Assert.assertTrue(true);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.spockframework.spring7

import groovy.transform.CompileStatic
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import spock.mock.DetachedMockFactory

import java.util.concurrent.Executor

@CompileStatic
@Configuration
class TestConfig {
@Bean
Executor executor() {
new DetachedMockFactory().Stub(Executor)
}
}