DefaultWorldpayDeliveryAddressStrategy implements WorldpayDeliveryAddressStrategy { @Override public AddressModel getDeliveryAddress(final AbstractOrderModel abstractOrderModel) { if (abstractOrderModel.getDeliveryAddress() == null) { final List<AbstractOrderEntryModel> entries = abstractOrderModel.getEntries(); for (final AbstractOrderEntryModel entry : entries) { if (entry.getDeliveryPointOfService() != null && entry.getDeliveryPointOfService().getAddress() != null) { return entry.getDeliveryPointOfService().getAddress(); } } throw new ConfigurationException(format("Checkout was attempted without a valid pickup or shipping address for cart with id [{0}]", abstractOrderModel.getCode())); } else { return abstractOrderModel.getDeliveryAddress(); } }  @Override AddressModel getDeliveryAddress(final AbstractOrderModel abstractOrderModel);  }
@Test public void shouldReturnDeliveryAddress() throws Exception { when(cartModelMock.getDeliveryAddress()).thenReturn(deliveryAddressModelMock); final AddressModel result = testObj.getDeliveryAddress(cartModelMock); assertEquals(deliveryAddressModelMock, result); }
@Test public void shouldReturnPickUpAddressIfDeliveryAddressIsNull() throws WorldpayConfigurationException { when(cartModelMock.getDeliveryAddress()).thenReturn(null); when(cartModelMock.getEntries()).thenReturn(singletonList(orderEntryModelMock)); when(orderEntryModelMock.getDeliveryPointOfService().getAddress()).thenReturn(pickupAddressModelMock); final AddressModel result = testObj.getDeliveryAddress(cartModelMock); assertEquals(pickupAddressModelMock, result); }