Skip to content

Instantly share code, notes, and snippets.

@mlevvy
Created November 26, 2015 08:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlevvy/948e13414be360a20212 to your computer and use it in GitHub Desktop.
Save mlevvy/948e13414be360a20212 to your computer and use it in GitHub Desktop.
Problem with @CompileStatic, SpreadOperator and calling a function
package pl.klkl
import groovy.transform.CompileStatic
import spock.lang.Specification
class GroovySpreadOperatorTest extends Specification {
interface Service {
List<Integer> heavyOperation()
}
@CompileStatic
List<String> invokeCompileStatic(Service service){
service.heavyOperation()*.toString()
}
List<String> invoke(Service service){
service.heavyOperation()*.toString()
}
//This test is failing. heavyOperation is called twice.
def "should be called once - with compile static"() {
given:
Service external = Mock(Service)
1 * external.heavyOperation() >> [0]
when:
def result = invokeCompileStatic(external)
then:
result == ["0"]
}
def "should be called once - without compile static"() {
given:
Service external = Mock(Service)
1 * external.heavyOperation() >> [0]
when:
def result = invoke(external)
then:
result == ["0"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment