GooglePayController extends AbstractCheckoutController { protected void saveBillingAddresses(final GooglePayAddressData address) { final AddressData addressData = new AddressData(); addressData.setBillingAddress(true); addressData.setFirstName(address.getName()); addressData.setLine1(address.getAddress1()); addressData.setLine2(StringUtils.join(new String[]{address.getAddress2(), address.getAddress3()}, " ").trim()); addressData.setTown(address.getLocality()); addressData.setPostalCode(address.getPostalCode()); addressData.setCountry(i18NFacade.getCountryForIsocode(address.getCountryCode())); addressData.setEmail(checkoutCustomerStrategy.getCurrentUserForCheckout().getContactEmail()); setRegion(addressData, address); userFacade.addAddress(addressData); worldpayPaymentCheckoutFacade.setBillingDetails(addressData); }  @RequireHardLogIn @PostMapping(value = "/authorise-order", consumes = {MediaType.APPLICATION_JSON_VALUE}) DirectResponseData authoriseOrder(@RequestBody final GooglePayAuthorisationRequest authorisationRequest);  }
@Test public void testAddressPopulation() { final GooglePayAddressData billingAddress = new GooglePayAddressData(); billingAddress.setAddress1("Av Aragon 30"); billingAddress.setAddress2("Planta 8 oficina 999"); billingAddress.setAddress3("lol"); billingAddress.setLocality("Valencia"); billingAddress.setCountryCode("ES"); billingAddress.setName("James Bond"); billingAddress.setPostalCode("46015"); final String email = "test@test.com"; when(customer.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); }