Skip to content

Instantly share code, notes, and snippets.

@AlicanAkkus
Created May 4, 2019 20:00
Show Gist options
  • Save AlicanAkkus/b98b55799a48d3396eb544b9425d45c3 to your computer and use it in GitHub Desktop.
Save AlicanAkkus/b98b55799a48d3396eb544b9425d45c3 to your computer and use it in GitHub Desktop.
order create with exception
package io.happy.customer
import spock.lang.Specification
class OrderCreateFacadeTest extends Specification {
def orderCommissionCalculator = Mock(OrderCommissionCalculator)
def orderCreateFacade = new OrderCreateFacade(orderCommissionCalculator)
void "should not create order when price is zero"() {
given:
def userId = 998
def paymentMethod = "CARD"
def price = 0
and:
1 * orderCommissionCalculator.calculate("CARD", 0) >> { throw new Exception("price could not be zero") }
0 * _._
when:
orderCreateFacade.create(userId, paymentMethod, price)
then:
def e = thrown(Exception)
e.message == "price could not be zero"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment