Last active
December 11, 2019 16:08
-
-
Save mario-rezende-ifood/27b0522e617178b7111e80d59e718160 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