### Question:
DeliveryService { public void createDelivery(long orderId, long restaurantId, Address deliveryAddress) { Restaurant restaurant = restaurantRepository.findById(restaurantId).get(); deliveryRepository.save(Delivery.create(orderId, restaurantId, restaurant.getAddress(), deliveryAddress)); } 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 shouldCreateDelivery() { when(restaurantRepository.findById(RESTAURANT_ID)).thenReturn(Optional.of(restaurant)); when(restaurant.getAddress()).thenReturn(DeliveryServiceTestData.PICKUP_ADDRESS); deliveryService.createDelivery(ORDER_ID, RESTAURANT_ID, DeliveryServiceTestData.DELIVERY_ADDRESS); ArgumentCaptor<Delivery> arg = ArgumentCaptor.forClass(Delivery.class); verify(deliveryRepository).save(arg.capture()); Delivery delivery = arg.getValue(); assertNotNull(delivery); assertEquals(ORDER_ID, delivery.getId()); assertEquals(DeliveryState.PENDING, delivery.getState()); assertEquals(RESTAURANT_ID, delivery.getRestaurantId()); assertEquals(DeliveryServiceTestData.PICKUP_ADDRESS, delivery.getPickupAddress()); assertEquals(DeliveryServiceTestData.DELIVERY_ADDRESS, delivery.getDeliveryAddress()); }