Forked from mario-rezende-ifood/mock-examples.groovy
Created
December 11, 2019 16:05
-
-
Save mariorez/608331d6c6414bf19d4e6211e693d3fb 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