DefaultWorldpayPaymentCheckoutFacade implements WorldpayPaymentCheckoutFacade { @Override public void setBillingDetails(final AddressData addressData) { final CartModel cartModel = getCart(); if (cartModel != null && addressData != null) { Optional.ofNullable(customerAccountService.getAddressForCode((CustomerModel) cartModel.getUser(), addressData.getId())) .ifPresent(addressModel -> worldpayCheckoutService.setPaymentAddress(cartModel, addressModel)); } } DefaultWorldpayPaymentCheckoutFacade(final CheckoutFacade checkoutFacade, final WorldpayCheckoutService worldpayCheckoutService, final CartService cartService, final CustomerAccountService customerAccountService); @Override void setBillingDetails(final AddressData addressData); @Override boolean hasBillingDetails();  }
@Test public void setBillingDetailsSetsPaymentAddressWhenPkMatchesAddressDataId() { when(addressDataMock.getId()).thenReturn(ADDRESS_DATA_ID); when(customerAccountServiceMock.getAddressForCode(customerModelMock, ADDRESS_DATA_ID)).thenReturn(addressModelMock); testObj.setBillingDetails(addressDataMock); verify(worldpayCheckoutServiceMock).setPaymentAddress(cartModelMock, addressModelMock); }
@Test public void setBillingDetailsDoesNotSetPaymentAddressWhenPkDoesNotMatchesAddressDataId() { when(addressDataMock.getId()).thenReturn(ADDRESS_DATA_ID); when(customerAccountServiceMock.getAddressForCode(customerModelMock, ADDRESS_DATA_ID)).thenReturn(null); testObj.setBillingDetails(addressDataMock); verify(worldpayCheckoutServiceMock, never()).setPaymentAddress(cartModelMock, addressModelMock); }
@Test public void setBillingDetailsDoesNotSetPaymentAddressWhenNoDeliveryAddressesReturned() { when(addressDataMock.getId()).thenReturn(ADDRESS_DATA_ID); when(customerAccountServiceMock.getAddressForCode(customerModelMock, ADDRESS_DATA_ID)).thenReturn(null); testObj.setBillingDetails(addressDataMock); verify(worldpayCheckoutServiceMock, never()).setPaymentAddress(cartModelMock, addressModelMock); }