import spock.lang.* class ChainedStubbing extends Specification { def "throw exception after returning three elements"() { Queue q = Mock() q.remove() >>> [1, 2, 3] >> { throw new NoSuchElementException() } expect: q.remove() == 1 q.remove() == 2 q.remove() == 3 when: q.remove() then: thrown(NoSuchElementException) when: q.remove() then: thrown(NoSuchElementException) } }