Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Publisher {
List<Subscriber> subscribers = []
void send(String message){
subscribers*.receive(message)
}
}
interface Subscriber {
void receive(String message)
}
class PublisherSpec extends Specification {
Publisher publisher = new Publisher()
Subscriber subscriber1 = Mock()
Subscriber subscriber2 = Mock()
def setup() {
publisher.subscribers << subscriber1 // << operador do Groovy para List.add()
publisher.subscribers << subscriber2
}
def 'should send messages to all subscribers'() {
when:
publisher.send("hello")
then:
1 * subscriber1.receive("hello")
1 * subscriber2.receive("hello")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment