spockframework / spockframework/spock
Mocking fails with reactive endpoints in spring-boot v3
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
After switching to spring-boot v3.x.x and groovy v4.0.9 with spock v2.4-M1-groovy-4.0 tests for a reactive (spring-webflux) controller with usage of org.springframework.test.web.reactive.server.WebTestClient in combination with mocked spring-services fail, when a given mocked instance has more than one (in another example less than three) interactions. The first interaction (or the first two interactions) are successfull and the defined value is returned for the mocked call. Further interactions fall back to the default behviour of returning null. Furthermore, these interactions are not counted.
To Reproduce
My team wrote an example project to demonstrate the behaviour. With spring-boot v3.0.4 several tests are failing. If you switch back to spring-boot v2.7.9, all test cases pass.
Expected behavior
All tests pass, independent of the spring-boot version.
Actual behavior
By using a mocked service within a reactor.core.publisher.Flux, the described behaviour is reproduceable
Java version
openjdk 17.0.4 2022-07-19 LTS
OpenJDK Runtime Environment Zulu17.36+13-CA (build 17.0.4+8-LTS)
OpenJDK 64-Bit Server VM Zulu17.36+13-CA (build 17.0.4+8-LTS, mixed mode, sharing)
Buildtool version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: C:\Program Files\maven
Java version: 17.0.4, vendor: Azul Systems, Inc., runtime: C:\Program Files\Java\jdk17
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
What operating system are you using
Windows
Dependencies
com.example.maybe.bug:bug-hunting🫙0.0.1-SNAPSHOT
+- org.springframework.boot:spring-boot-starter-webflux🫙3.0.4:compile
| +- org.springframework.boot:spring-boot-starter🫙3.0.4:compile
| | +- org.springframework.boot:spring-boot🫙3.0.4:compile
| | | - org.springframework:spring-context🫙6.0.6:compile
| | | +- org.springframework:spring-aop🫙6.0.6:compile
| | | - org.springframework:spring-expression🫙6.0.6:compile
| | +- org.springframework.boot:spring-boot-autoconfigure🫙3.0.4:compile
| | +- org.springframework.boot:spring-boot-starter-logging🫙3.0.4:compile
| | | +- ch.qos.logback:logback-classic🫙1.4.5:compile
| | | | - ch.qos.logback:logback-core🫙1.4.5:compile
| | | +- org.apache.logging.log4j:log4j-to-slf4j🫙2.19.0:compile
| | | | - org.apache.logging.log4j:log4j-api🫙2.19.0:compile
| | | - org.slf4j:jul-to-slf4j🫙2.0.6:compile
| | +- jakarta.annotation:jakarta.annotation-api🫙2.1.1:compile
| | - org.yaml:snakeyaml🫙1.33:compile
| +- org.springframework.boot:spring-boot-starter-json🫙3.0.4:compile
| | +- com.fasterxml.jackson.core:jackson-databind🫙2.14.2:compile
| | | +- com.fasterxml.jackson.core:jackson-annotations🫙2.14.2:compile
| | | - com.fasterxml.jackson.core:jackson-core🫙2.14.2:compile
| | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8🫙2.14.2:compile
| | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310🫙2.14.2:compile
| | - com.fasterxml.jackson.module:jackson-module-parameter-names🫙2.14.2:compile
| +- org.springframework.boot:spring-boot-starter-reactor-netty🫙3.0.4:compile
| | - io.projectreactor.netty:reactor-netty-http🫙1.1.4:compile
| | +- io.netty:netty-codec-http🫙4.1.89.Final:compile
| | | +- io.netty:netty-common🫙4.1.89.Final:compile
| | | +- io.netty:netty-buffer🫙4.1.89.Final:compile
| | | +- io.netty:netty-transport🫙4.1.89.Final:compile
| | | +- io.netty:netty-codec🫙4.1.89.Final:compile
| | | - io.netty:netty-handler🫙4.1.89.Final:compile
| | +- io.netty:netty-codec-http2🫙4.1.89.Final:compile
| | +- io.netty:netty-resolver-dns🫙4.1.89.Final:compile
| | | +- io.netty:netty-resolver🫙4.1.89.Final:compile
| | | - io.netty:netty-codec-dns🫙4.1.89.Final:compile
| | +- io.netty:netty-resolver-dns-native-macos🫙osx-x86_64:4.1.89.Final:compile
| | | - io.netty:netty-resolver-dns-classes-macos🫙4.1.89.Final:compile
| | +- io.netty:netty-transport-native-epoll🫙linux-x86_64:4.1.89.Final:compile
| | | +- io.netty:netty-transport-native-unix-common🫙4.1.89.Final:compile
| | | - io.netty:netty-transport-classes-epoll🫙4.1.89.Final:compile
| | - io.projectreactor.netty:reactor-netty-core🫙1.1.4:compile
| | - io.netty:netty-handler-proxy🫙4.1.89.Final:compile
| | - io.netty:netty-codec-socks🫙4.1.89.Final:compile
| +- org.springframework:spring-web🫙6.0.6:compile
| | +- org.springframework:spring-beans🫙6.0.6:compile
| | - io.micrometer:micrometer-observation🫙1.10.4:compile
| | - io.micrometer:micrometer-commons🫙1.10.4:compile
| - org.springframework:spring-webflux🫙6.0.6:compile
+- org.springframework.boot:spring-boot-starter-test🫙3.0.4:test
| +- org.springframework.boot:spring-boot-test🫙3.0.4:test
| +- org.springframework.boot:spring-boot-test-autoconfigure🫙3.0.4:test
| +- com.jayway.jsonpath:json-path🫙2.7.0:test
| | +- net.minidev:json-smart🫙2.4.8:test
| | | - net.minidev:accessors-smart🫙2.4.8:test
| | | - org.ow2.asm:asm🫙9.1:test
| | - org.slf4j:slf4j-api🫙2.0.6:compile
| +- jakarta.xml.bind:jakarta.xml.bind-api🫙4.0.0:test
| | - jakarta.activation:jakarta.activation-api🫙2.1.1:test
| +- org.assertj:assertj-core🫙3.23.1:test
| | - net.bytebuddy:byte-buddy🫙1.12.23:test
| +- org.hamcrest:hamcrest🫙2.2:test
| +- org.junit.jupiter:junit-jupiter🫙5.9.2:test
| | +- org.junit.jupiter:junit-jupiter-api🫙5.9.2:test
| | +- org.junit.jupiter:junit-jupiter-params🫙5.9.2:test
| | - org.junit.jupiter:junit-jupiter-engine🫙5.9.2:test
| +- org.mockito:mockito-core🫙4.8.1:test
| | +- net.bytebuddy:byte-buddy-agent🫙1.12.23:test
| | - org.objenesis:objenesis🫙3.2:test
| +- org.mockito:mockito-junit-jupiter🫙4.8.1:test
| +- org.skyscreamer:jsonassert🫙1.5.1:test
| | - com.vaadin.external.google:android-json🫙0.0.20131108.vaadin1:test
| +- org.springframework:spring-core🫙6.0.6:compile
| | - org.springframework:spring-jcl🫙6.0.6:compile
| +- org.springframework:spring-test🫙6.0.6:test
| - org.xmlunit:xmlunit-core🫙2.9.1:test
+- io.projectreactor:reactor-test🫙3.5.3:test
| - io.projectreactor:reactor-core🫙3.5.3:compile
| - org.reactivestreams:reactive-streams🫙1.0.4:compile
+- org.apache.groovy:groovy🫙4.0.9:test
+- org.apache.groovy:groovy-json🫙4.0.9:test
+- org.spockframework:spock-core🫙2.4-M1-groovy-4.0:test
| - org.junit.platform:junit-platform-engine🫙1.9.2:test
| +- org.opentest4j:opentest4j🫙1.2.0:test
| +- org.junit.platform:junit-platform-commons🫙1.9.2:test
| - org.apiguardian:apiguardian-api🫙1.1.2:test
- org.spockframework:spock-spring🫙2.4-M1-groovy-4.0:test
Additional context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the attached maybe-bug-discovered.zip example with spring-boot 3.0.4, then compare its tests with spring-boot 2.7.9. Done means the reactive WebTestClient cases pass in both versions, with every mocked interaction counted and its defined value returned.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java, spring-boot
- Domain
- backend, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100