Description
Describe the bug
In Groovy, it is possible to declare a getter method for a returned Boolean value, where the prefix get
can be replaced by is
. A subsequent reference to such a method in shorthand notation works correctly in both cases, but Spock cannot correctly mock such a method when the shorthand notation is used.
To Reproduce
Consider the following example specification:
class SimpleSpecification extends Specification {
def 'test stub assertions'(VcsDetails vcsDetails) {
expect:
verifyAll(vcsDetails) {
lastTag == 'current-tag'
cleanTag == true
isCleanTag == true
}
where:
vcsDetails << [
Stub(VcsDetails) {
lastTag >> 'current-tag'
cleanTag >> true // condition will be NOT satisfied
isCleanTag >> true
},
Stub(VcsDetails) {
lastTag >> 'current-tag'
isCleanTag() >> true // condition will be satisfied
isCleanTag >> true
},
]
}
static interface VcsDetails {
String getLastTag()
Boolean isCleanTag()
Boolean getIsCleanTag()
}
}
Expected behavior
Spock will correctly mock the isCleanTag()
method using shorthand.
Actual behavior
Spock does not mock the isCleanTag()
method using a shorthand. The example specification posted ends with an error only for the first test case, where shorthand is used.
test stub assertions [vcsDetails: Mock for type 'VcsDetails', #0]
Condition not satisfied:
cleanTag == true
| |
false false
at com.example.SimpleSpecification.test stub assertions_closure1(SimpleSpecification.groovy:10)
at app//groovy.lang.Closure.call(Closure.java:412)
at app//spock.lang.Specification.verifyAll(Specification.java:276)
at com.example.SimpleSpecification.test stub assertions(SimpleSpecification.groovy:8)
Java version
openjdk 11.0.26 2025-01-21
OpenJDK Runtime Environment Temurin-11.0.26+4 (build 11.0.26+4)
OpenJDK 64-Bit Server VM Temurin-11.0.26+4 (build 11.0.26+4, mixed mode)
Buildtool version
Gradle 8.2.1
Build time: 2023-07-10 12:12:35 UTC
Revision: a38ec64d3c4612da9083cc506a1ccb212afeecaa
Kotlin: 1.8.20
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 11.0.26 (Eclipse Adoptium 11.0.26+4)
OS: Linux 6.13.6-200.fc41.x86_64 amd64
What operating system are you using
Linux
Dependencies
+--- org.spockframework:spock-core:2.3-groovy-3.0
| +--- org.junit:junit-bom:5.9.0
| | +--- org.junit.platform:junit-platform-engine:1.9.0 (c)
| | +--- org.junit.platform:junit-platform-launcher:1.9.0 (c)
| | --- org.junit.platform:junit-platform-commons:1.9.0 (c)
| +--- org.junit.platform:junit-platform-engine -> 1.9.0
| | +--- org.junit:junit-bom:5.9.0 ()
| | +--- org.opentest4j:opentest4j:1.2.0
| | --- org.junit.platform:junit-platform-commons:1.9.0
| | --- org.junit:junit-bom:5.9.0 ()
| --- org.hamcrest:hamcrest:2.2
+--- net.bytebuddy:byte-buddy:[1.14.0,1.15.0) -> 1.14.19
--- org.objenesis:objenesis:[3.4,3.5) -> 3.4
Additional context
No response