Forked from mario-rezende-ifood/stubbing-spock.groovy
Created
December 11, 2019 16:08
-
-
Save mariorez/e76e5e95aa1cc3e15bd413642134d02a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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