Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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