Last active
July 16, 2020 13:49
-
-
Save mucahitkurt/b247617ad01d03b8837c48407dd7c5ef 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 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