OrderFinder { public Order findById(String orderId) { return orderRepository.findById(orderId).orElseThrow(() -> new OrderNotFoundException(orderId)); } OrderFinder(OrderRepository orderRepository); Order findById(String orderId);  }
@Test void shouldReturnAnOrder_whenFound() { var order = new Order(); order.setOrderId(ORDER_ID); BDDMockito.given(orderRepository.findById(ORDER_ID)).willReturn(Optional.of(order)); var orderFound = orderFinder.findById(ORDER_ID); Assertions.assertNotNull(orderFound); Assertions.assertEquals(ORDER_ID, orderFound.getOrderId()); }
@Test void shouldThrowOrderNotFoundException_whenNotFound() { BDDMockito.given(orderRepository.findById(ORDER_ID)).willReturn(Optional.empty()); Assertions.assertThrows(OrderNotFoundException.class, () -> orderFinder.findById(ORDER_ID)); }