Skip to content

Instantly share code, notes, and snippets.

@AlicanAkkus
Last active May 4, 2019 19:54
Show Gist options
  • Save AlicanAkkus/5772cc3e40ccbbe4849a27b8efb855b0 to your computer and use it in GitHub Desktop.
Save AlicanAkkus/5772cc3e40ccbbe4849a27b8efb855b0 to your computer and use it in GitHub Desktop.
interaction based test
package io.happy.customer
import spock.lang.Specification
class OrderCreateFacadeTest extends Specification {
def orderCommissionCalculator = Mock(OrderCommissionCalculator)
def orderCreateFacade = new OrderCreateFacade(orderCommissionCalculator)
void "should create order and verify interactions"() {
given:
def userId = 998
def paymentMethod = "CARD"
def price = 100
and:
1 * orderCommissionCalculator.calculate("CARD", 100) >> 2.3
0 * _._
when:
def order = orderCreateFacade.create(userId, paymentMethod, price)
then:
with(order) {
it.userId == 998
it.paymentMethod == "CARD"
it.price == 100
it.commissionAmount == 2.3
it.orderCreatedDate.toLocalDate()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment