Skip to content

Instantly share code, notes, and snippets.

View mario-rezende-ifood's full-sized avatar

Mario Rezende mario-rezende-ifood

  • iFood
  • Sao Paulo / Brazil
View GitHub Profile
Subscriber subscriber1 = Mock()
Subscriber subscriber2 = Mock()
class Publisher {
List<Subscriber> subscribers = []
void send(String message){
subscribers*.receive(message)
}
}
interface Subscriber {
void receive(String message)
}
1 * subscriber1.receive("hello")
| | | |
| | | restrição de argumento
| | restrição de método
| restrição de alvo
restrição por cardinalidade
class Publisher {
private Subscriber subscriber
Publisher(Subscriber subscriber) {
this.subscriber = subscriber
}
String sendAndGetStatus(String message) {
return subscriber.receive(message)
}
subscriber.receive(_) >> "ok"
| | | |
| | | gerador de resposta
| | argumento de restrição
| método de restrição
objeto de restrição
given:
def stack = new Stack()
when:
stack.pop()
then:
thrown(EmptyStackException)
stack.empty
subscriber.receive(_) >> { throw new InternalError("ouch") }