Yes it is possible.
someObject.someMethod(*_) >>> [ 'x', 'y' ]
It will return xon the first call and yon the second method call.
Example:
void "test something"() {
given:
def sample = Mock(Sample){
someMethod(_) >>> [ 'Hello', 'World' ]
}
expect:
sample.someMethod( 'foo' ) == 'Hello'
sample.someMethod( 'bar' ) == 'World'
}
class Sample {
def someMethod(def a) {
return a
}
}
source
share