Recall the stub method

3 views
Skip to first unread message

Johnny Jian

unread,
Feb 19, 2010, 3:53:50 AM2/19/10
to gmoc...@googlegroups.com
I have tidied the DSL for the stub method as below. Please check it out. If there is no problem, I will raise an issue for it.

def mailer = stub(MailService)

mailer.toString().returns('mailer') // the toString method with no parameters will return 'mailer'
mailer.reset().raises(RuntimeException)
mailer.send(_).returns(true) // the send method with any number of any parameter will return true
mailer.receive(1000).returns('list of mails')
mailer.title = 'some title'

play {
    assert mailer.send('test')
    assert mailer.send(1, 2)
    assert 'some title' == mailer.title
    mailer.address = 'another address'
}

assert !mailer.send().called
assert mailer.send(_).called
assert mailer.send(_).called == 2
assert mailer.send(_)[0][0] == 'test'
assert mailer.send(_)[1] == [1, 2]
assert mailer.send('test').called == 1

assert mailer.address == 'another address'

Johnny
2010-02-19
Reply all
Reply to author
Forward
0 new messages