Last active
December 11, 2019 16:05
-
-
Save mario-rezende-ifood/6458d8fd533bee186a4fe59c12f320c9 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 { | |
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