Spock Web Console

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

CandyBox

Published 3 years ago by candy-san
Actions  ➤ Edit In Console Back To Console Show/Hide Line Numbers View Recent Scripts
import spock.lang.*

class CandyBoxSpec extends Specification {
  def "shake a box, all candies are detonated once"() {
    List<Candy> candies = new ArrayList<Candy>()
    Candy c1 = Mock()
    candies.add(c1)
    CandyBox box = new CandyBox(candies)
    when:
    box.shake()
box.shake()
    then:
    1 * c1.detonate()
  }
}
class CandyBox {
    List<Candy> candies
    CandyBox(List<Candy> candies) { this.candies = candies}
    public void shake() {
        candies.each {it.detonate()}
    }
}
interface Candy {
    String detonate()
}