DefaultWorldpayApplePayPaymentCheckoutFacade implements WorldpayApplePayPaymentCheckoutFacade { @Override public void saveBillingAddresses(final ApplePayPaymentContact billingContact) { final AddressData addressData = new AddressData(); addressData.setBillingAddress(true); addressData.setFirstName(billingContact.getGivenName()); addressData.setLastName(billingContact.getFamilyName()); if (billingContact.getAddressLines().size() >= 1) { addressData.setLine1(IterableUtils.get(billingContact.getAddressLines(), 0)); } if (billingContact.getAddressLines().size() > 1) { addressData.setLine2(IterableUtils.get(billingContact.getAddressLines(), 1)); } addressData.setTown(billingContact.getAdministrativeArea()); addressData.setPostalCode(billingContact.getPostalCode()); addressData.setCountry(i18NFacade.getCountryForIsocode(StringUtils.upperCase(billingContact.getCountryCode()))); addressData.setEmail(checkoutCustomerStrategy.getCurrentUserForCheckout().getContactEmail()); setRegion(addressData, billingContact); userFacade.addAddress(addressData); worldpayPaymentCheckoutFacade.setBillingDetails(addressData); }  @Override void saveBillingAddresses(final ApplePayPaymentContact billingContact); @Override void setRegion(final AddressData addressData, final ApplePayPaymentContact address); @Override ValidateMerchantRequestDTO getValidateMerchantRequestDTO(); @Required void setWorldpayPaymentCheckoutFacade(WorldpayPaymentCheckoutFacade worldpayPaymentCheckoutFacade); @Required void setI18NFacade(I18NFacade i18NFacade); @Required void setCheckoutCustomerStrategy(CheckoutCustomerStrategy checkoutCustomerStrategy); @Required void setUserFacade(UserFacade userFacade); @Required void setWorldpayMerchantConfigDataFacade(WorldpayMerchantConfigDataFacade worldpayMerchantConfigDataFacade); @Required void setApplePayConfigDataToValidateMerchantRequestDTOPopulatingConverter(Converter<ApplePayConfigData, ValidateMerchantRequestDTO> applePayConfigDataToValidateMerchantRequestDTOPopulatingConverter);  }
@Test public void testAddressPopulation() { doNothing().when(worldpayPaymentCheckoutFacadeMock).setBillingDetails(any(AddressData.class)); final ApplePayPaymentContact billingAddress = new ApplePayPaymentContact(); billingAddress.setAddressLines(Arrays.asList("Av Aragon 30", "Planta 8 oficina 999")); billingAddress.setAdministrativeArea("Valencia"); billingAddress.setCountryCode("es"); billingAddress.setGivenName("James"); billingAddress.setFamilyName("Bond"); billingAddress.setPostalCode("46015"); final String email = "test@test.com"; when(customerMock.getContactEmail()).thenReturn(email); final CountryData country = mock(CountryData.class); when(i18NFacadeMock.getCountryForIsocode("ES")).thenReturn(country); testObj.saveBillingAddresses(billingAddress); verify(checkoutCustomerStrategyMock).getCurrentUserForCheckout(); verify(userFacadeMock).addAddress(addressCaptor.capture()); verifyAddress(addressCaptor, country); verify(worldpayPaymentCheckoutFacadeMock).setBillingDetails(addressCaptor.capture()); verifyAddress(addressCaptor, country); }