WorldpayHopResponseController extends WorldpayChoosePaymentMethodCheckoutStepController { @RequestMapping(value = "/billingaddressform", method = RequestMethod.GET) public String getCountryAddressForm(@RequestParam("countryIsoCode") final String countryIsoCode, @RequestParam("useDeliveryAddress") final boolean useDeliveryAddress, final Model model) { model.addAttribute("supportedCountries", getCountries()); model.addAttribute("regions", getI18NFacade().getRegionsForCountryIso(countryIsoCode)); model.addAttribute("country", countryIsoCode); final PaymentDetailsForm wpPaymentDetailsForm = new PaymentDetailsForm(); model.addAttribute(BILLING_ADDRESS_FORM, wpPaymentDetailsForm); if (useDeliveryAddress) { populateAddressForm(countryIsoCode, wpPaymentDetailsForm); } return worldpayAddonEndpointService.getBillingAddressForm(); }  @RequireHardLogIn @RequestMapping(value = "/hop-response", method = RequestMethod.GET) String doHandleHopResponse(final HttpServletRequest request, final Model model, final RedirectAttributes redirectAttributes); @RequireHardLogIn @RequestMapping(value = "/hop-pending", method = RequestMethod.GET) String doHandlePendingHopResponse(final HttpServletRequest request, final Model model, final RedirectAttributes redirectAttributes); @RequireHardLogIn @RequestMapping(value = "bank-transfer/hop-response", method = RequestMethod.GET) String doHandleBankTransferHopResponse(final HttpServletRequest request, final Model model, final RedirectAttributes redirectAttributes); @RequireHardLogIn @RequestMapping(value = "bank-transfer/hop-failure", method = RequestMethod.GET) String doHandleBankTransferHopFailure(final HttpServletRequest request, final RedirectAttributes redirectAttributes); @RequestMapping(value = "/hop-cancel", method = RequestMethod.GET) @RequireHardLogIn String doCancelPayment(); @RequestMapping(value = "/error", method = RequestMethod.GET) @RequireHardLogIn String doHostedOrderPageError(@RequestParam(value = "paymentStatus", required = false) final String paymentStatus, final RedirectAttributes redirectAttributes); @RequestMapping(value = "/billingaddressform", method = RequestMethod.GET) String getCountryAddressForm(@RequestParam("countryIsoCode") final String countryIsoCode,
                                        @RequestParam("useDeliveryAddress") final boolean useDeliveryAddress, final Model model);  }
@Test public void shouldPopulateBillingAddressWithShippingAddress() { when(checkoutFacadeMock.getCheckoutCart()).thenReturn(cartDataMock); when(cartDataMock.getDeliveryAddress()).thenReturn(deliveryAddressMock); when(deliveryAddressMock.getTitleCode()).thenReturn(TITLE); when(deliveryAddressMock.getFirstName()).thenReturn(FIRST_NAME); when(deliveryAddressMock.getLastName()).thenReturn(LAST_NAME); when(deliveryAddressMock.getLine1()).thenReturn(LINE_1); when(deliveryAddressMock.getLine2()).thenReturn(LINE_2); when(deliveryAddressMock.getTown()).thenReturn(TOWN); when(deliveryAddressMock.getPostalCode()).thenReturn(POSTAL_CODE); when(deliveryAddressMock.getPhone()).thenReturn(PHONE_NUMBER); final List<RegionData> regionDataInfos = singletonList(regionDataMock); when(i18NFacade.getRegionsForCountryIso(COUNTRY_ISO_CODE)).thenReturn(regionDataInfos); testObj.getCountryAddressForm(COUNTRY_ISO_CODE, true, modelMock); verify(modelMock).addAttribute(eq(BILLING_ADDRESS_FORM), paymentDetailsFormArgumentCaptor.capture()); verify(modelMock).addAttribute("supportedCountries", checkoutFacadeMock.getDeliveryCountries()); verify(modelMock).addAttribute("regions", regionDataInfos); verify(modelMock).addAttribute("country", COUNTRY_ISO_CODE); final PaymentDetailsForm paymentDetailsForm = paymentDetailsFormArgumentCaptor.getValue(); assertEquals(FIRST_NAME, paymentDetailsForm.getBillingAddress().getFirstName()); assertEquals(LAST_NAME, paymentDetailsForm.getBillingAddress().getLastName()); assertEquals(LINE_1, paymentDetailsForm.getBillingAddress().getLine1()); assertEquals(LINE_2, paymentDetailsForm.getBillingAddress().getLine2()); assertEquals(TOWN, paymentDetailsForm.getBillingAddress().getTownCity()); assertEquals(POSTAL_CODE, paymentDetailsForm.getBillingAddress().getPostcode()); assertEquals(COUNTRY_ISO_CODE, paymentDetailsForm.getBillingAddress().getCountryIso()); assertEquals(PHONE_NUMBER, paymentDetailsForm.getBillingAddress().getPhone()); assertEquals(TITLE, paymentDetailsForm.getBillingAddress().getTitleCode()); }