I'm writing Spock tests, and used an inline closure to stub for simple fail/pass behaviour.
def "test timeout"() {
given:
2 * feignClient.poll("foo") >>
{
int retries = 0;
if (retries < 1) {
retries++
throw newRetryable()
}
pollWaitSuccessResponseEntity
}
So I tried to refactor the closure to a named Closure:
def retryClosure = {
int retries = 0;
if (retries < 1) {
retries++
throw newRetryable()
}
pollWaitSuccessResponseEntity
}
2 * feignClient.poll("foo") >> retryClosure
The test fails with the following error:
Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast object
'com.example.service.FooServiceTest$__spock_initializeFields_closure2@3243178c' with class 'com.example..FooServiceTest$__spock_initializeFields_closure2' to class 'org.springframework.http.ResponseEntity'