Spock Web Console

subscribe to the feed Subscribe
Chained Stubbing (via #spockwebconsole)
tweet this script Tweet

Chained Stubbing

Published 2 years ago by Peter Niederwieser with tags new-0.6 stubbing mocking
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
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)
  }
}