Skip to content

Instantly share code, notes, and snippets.

@mariorez
Forked from mario-rezende-ifood/stubbing-spock.groovy
Created December 11, 2019 16:08
Show Gist options
  • Save mariorez/e76e5e95aa1cc3e15bd413642134d02a to your computer and use it in GitHub Desktop.
Save mariorez/e76e5e95aa1cc3e15bd413642134d02a to your computer and use it in GitHub Desktop.
class Publisher {
private Subscriber subscriber
Publisher(Subscriber subscriber) {
this.subscriber = subscriber
}
String sendAndGetStatus(String message) {
return subscriber.receive(message)
}
}
interface Subscriber {
String receive(String message)
}
class PublisherSpec extends Specification {
Publisher publisher
Subscriber subscriber = Mock()
def setup() {
subscriber.receive(_) >> "ok" // Stubbing
publisher = new Publisher(subscriber)
}
def 'should send messages and get the subscriber status'() {
when:
def result = publisher.sendAndGetStatus("hello")
then:
result == "ok"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment