spockframework / spockframework/spock
GroovyMock object on a final class doesn't work properly inside statically compiled service
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3.6k
- Forks
- 483
- PR merge metrics
- No merged PRs in 30d
Description
Issue description
GroovyMock interactions for final class doesn't work inside@CompileStatic annotated class or in plain java class. In this case mock object will use real method implementation instead of provided interaction.
Minimal code to reproduce
import groovy.transform.CompileStatic
import spock.lang.Specification
class UserServiceSpec extends Specification {
def "test final class mock interactions"() {
setup:
def mock = GroovyMock(FinalClass) {
getName() >> "Foo Bar"
}
when:
new StaticService().getName(mock)
then:
thrown(UnsupportedOperationException)
expect:
new GroovyService().getName(mock) == "FOO BAR"
}
}
final class FinalClass {
String getName() {
throw new UnsupportedOperationException("Not implemented")
}
}
class GroovyService {
String getName(FinalClass obj) {
obj.name.toUpperCase()
}
}
@CompileStatic
class StaticService {
String getName(FinalClass obj) {
obj.name.toUpperCase()
}
}
Environment
Java: OpenJDK Runtime Environment (build 1.8.0_144-b01)
Gradle: 3.5
Gradle dependencies
compile 'org.codehaus.groovy:groovy-all:2.4.12'
compile 'org.spockframework:spock-core:1.1-groovy-2.4'
compile 'cglib:cglib-nodep:3.2.5'
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 with the minimal reproduction in the issue, comparing GroovyService and @CompileStatic StaticService when GroovyMock targets the final FinalClass; also check the plain Java case described. Trace the GroovyMock interaction path for the final class and verify that getName() uses the provided interaction rather than the real implementation in both statically compiled and Java callers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- groovy, java
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100