### Question:
DeliveryService { public void scheduleDelivery(long orderId, LocalDateTime readyBy) { Delivery delivery = deliveryRepository.findById(orderId).get(); List<Courier> couriers = courierRepository.findAllAvailable(); Courier courier = couriers.get(random.nextInt(couriers.size())); courier.addAction(Action.makePickup(delivery.getId(), delivery.getPickupAddress(), readyBy)); courier.addAction(Action.makeDropoff(delivery.getId(), delivery.getDeliveryAddress(), readyBy.plusMinutes(30))); delivery.schedule(readyBy, courier.getId()); } DeliveryService(RestaurantRepository restaurantRepository, DeliveryRepository deliveryRepository, CourierRepository courierRepository); void createRestaurant(long restaurantId, String restaurantName, Address address); void createDelivery(long orderId, long restaurantId, Address deliveryAddress); void scheduleDelivery(long orderId, LocalDateTime readyBy); void cancelDelivery(long orderId); @Transactional void updateAvailability(long courierId, boolean available); @Transactional Optional<DeliveryStatus> getDeliveryInfo(long deliveryId);  }### Answer:
@Test public void shouldScheduleDelivery() { Delivery delivery = Delivery.create(ORDER_ID, RESTAURANT_ID, DeliveryServiceTestData.PICKUP_ADDRESS, DeliveryServiceTestData.DELIVERY_ADDRESS); when(deliveryRepository.findById(ORDER_ID)).thenReturn(Optional.of(delivery)); when(courierRepository.findAllAvailable()).thenReturn(Collections.singletonList(courier)); deliveryService.scheduleDelivery(ORDER_ID, READY_BY); assertEquals(DeliveryState.SCHEDULED, delivery.getState()); assertSame(courier.getId(), delivery.getAssignedCourier()); List<Action> actions = courier.getPlan().getActions(); assertEquals(2, actions.size()); assertEquals(DeliveryActionType.PICKUP, actions.get(0).getType()); assertEquals(DeliveryServiceTestData.PICKUP_ADDRESS, actions.get(0).getAddress()); assertEquals(DeliveryActionType.DROPOFF, actions.get(1).getType()); assertEquals(DeliveryServiceTestData.DELIVERY_ADDRESS, actions.get(1).getAddress()); }