Skip to content

Instantly share code, notes, and snippets.

@mucahitkurt
Last active July 16, 2020 13:49
Show Gist options
  • Save mucahitkurt/b247617ad01d03b8837c48407dd7c5ef to your computer and use it in GitHub Desktop.
Save mucahitkurt/b247617ad01d03b8837c48407dd7c5ef to your computer and use it in GitHub Desktop.
class OrderService(val orderRepository: OrderRepository) {
fun cancelAllOrder(customer: Customer) {
val orders = orderRepository.findAllByCustomerAndOrderStatus(customer, OrderStatus.UNPAID)
//..
}
}
class OrderServiceTest {
@Test
fun `Should cancel all order of a customer if the all orders are unpaid`() {
val orderRepository = mockk<OrderRepository>()
val customer = Customer()
val order1 = Order(customer = customer, status = OrderStatus.UNPAID)
val order2 = Order(customer = customer, status = OrderStatus.UNPAID)
every { orderRepository.findAllByCustomerAndOrderStatus(customer, OrderStatus.UNPAID) } returns listOf(order1, order2)
val orderService = OrderService(orderRepository)
orderService.cancelAllOrder(customer)
assertTrue(order1.isCancelled())
assertTrue(order2.isCancelled())
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment