WorldpayChoosePaymentMethodCheckoutStepController extends AbstractWorldpayPaymentMethodCheckoutStepController { protected void populateAddressForm(final AddressData addressData, final AddressForm addressForm) { final RegionData region = addressData.getRegion(); if (region != null && !StringUtils.isEmpty(region.getIsocodeShort())) { addressForm.setRegionIso(region.getIsocodeShort()); } addressForm.setTitleCode(addressData.getTitle()); addressForm.setFirstName(addressData.getFirstName()); addressForm.setLastName(addressData.getLastName()); addressForm.setLine1(addressData.getLine1()); addressForm.setLine2(addressData.getLine2()); addressForm.setTownCity(addressData.getTown()); addressForm.setPostcode(addressData.getPostalCode()); addressForm.setCountryIso(addressData.getCountry().getIsocode()); addressForm.setPhone(addressData.getPhone()); }  @Override @RequestMapping(method = GET, value = {"", "/", "/add-cse-payment-details", "/add-payment-details"}) @RequireHardLogIn @PreValidateCheckoutStep(checkoutStep = CHOOSE_PAYMENT_METHOD) String enterStep(final Model model, final RedirectAttributes redirectAttributes); @RequestMapping(value = "/getDeclineMessage", method = GET) @ResponseBody String getDeclineMessage(); @RequestMapping(value = "/choose", method = GET) @RequireHardLogIn String doSelectPaymentMethod(@RequestParam("selectedPaymentMethodId") final String selectedPaymentMethodId); @ModelAttribute(value = "getTermsAndConditionsUrl") String getTermsAndConditionsUrl(final HttpServletRequest request); @RequestMapping(value = "/remove", method = POST) @RequireHardLogIn String remove(@RequestParam(value = "paymentInfoId") final String paymentMethodId,
                         final RedirectAttributes redirectAttributes); @RequestMapping(value = "/back", method = GET) @RequireHardLogIn @Override String back(final RedirectAttributes redirectAttributes); @RequestMapping(value = "/next", method = GET) @RequireHardLogIn @Override String next(final RedirectAttributes redirectAttributes); String getRedirectToPaymentMethod(); PaymentDetailsFormValidator getPaymentDetailsFormValidator(); MessageSource getThemeSource();  }
@Test public void testPopulateAddressFormWithRegionDataNull() { when(addressDataMock.getRegion()).thenReturn(null); when(addressDataMock.getTitle()).thenReturn(TITLE); when(addressDataMock.getFirstName()).thenReturn(FIRST_NAME); when(addressDataMock.getLastName()).thenReturn(LAST_NAME); when(addressDataMock.getLine1()).thenReturn(LINE_1); when(addressDataMock.getLine2()).thenReturn(LINE_2); when(addressDataMock.getTown()).thenReturn(TOWN); when(addressDataMock.getPostalCode()).thenReturn(POSTAL_CODE); when(addressDataMock.getPhone()).thenReturn(PHONE_NUMBER); when(addressDataMock.getCountry().getIsocode()).thenReturn(COUNTRY_ISO_CODE); testObj.populateAddressForm(addressDataMock, addressFormMock); verify(addressFormMock).setTitleCode(TITLE); verify(addressFormMock).setFirstName(FIRST_NAME); verify(addressFormMock).setLastName(LAST_NAME); verify(addressFormMock).setLine1(LINE_1); verify(addressFormMock).setLine2(LINE_2); verify(addressFormMock).setTownCity(TOWN); verify(addressFormMock).setPostcode(POSTAL_CODE); verify(addressFormMock).setCountryIso(COUNTRY_ISO_CODE); verify(addressFormMock).setPhone(PHONE_NUMBER); verify(addressFormMock, never()).setRegionIso(anyString()); }
@Test public void testPopulateAddressFormWithRegionDataEmptyString() { when(addressDataMock.getRegion().getIsocodeShort()).thenReturn(StringUtils.EMPTY); when(addressDataMock.getTitle()).thenReturn(TITLE); when(addressDataMock.getFirstName()).thenReturn(FIRST_NAME); when(addressDataMock.getLastName()).thenReturn(LAST_NAME); when(addressDataMock.getLine1()).thenReturn(LINE_1); when(addressDataMock.getLine2()).thenReturn(LINE_2); when(addressDataMock.getTown()).thenReturn(TOWN); when(addressDataMock.getPostalCode()).thenReturn(POSTAL_CODE); when(addressDataMock.getPhone()).thenReturn(PHONE_NUMBER); when(addressDataMock.getCountry().getIsocode()).thenReturn(COUNTRY_ISO_CODE); testObj.populateAddressForm(addressDataMock, addressFormMock); verify(addressFormMock).setTitleCode(TITLE); verify(addressFormMock).setFirstName(FIRST_NAME); verify(addressFormMock).setLastName(LAST_NAME); verify(addressFormMock).setLine1(LINE_1); verify(addressFormMock).setLine2(LINE_2); verify(addressFormMock).setTownCity(TOWN); verify(addressFormMock).setPostcode(POSTAL_CODE); verify(addressFormMock).setCountryIso(COUNTRY_ISO_CODE); verify(addressFormMock).setPhone(PHONE_NUMBER); verify(addressFormMock, never()).setRegionIso(anyString()); }
@Test public void testPopulateAddressFormWithRegionData() { when(addressDataMock.getRegion()).thenReturn(regionDataMock); when(addressDataMock.getRegion().getIsocodeShort()).thenReturn(REGION_ISO_CODE); when(addressDataMock.getTitle()).thenReturn(TITLE); when(addressDataMock.getFirstName()).thenReturn(FIRST_NAME); when(addressDataMock.getLastName()).thenReturn(LAST_NAME); when(addressDataMock.getLine1()).thenReturn(LINE_1); when(addressDataMock.getLine2()).thenReturn(LINE_2); when(addressDataMock.getTown()).thenReturn(TOWN); when(addressDataMock.getPhone()).thenReturn(PHONE_NUMBER); when(addressDataMock.getPostalCode()).thenReturn(POSTAL_CODE); when(addressDataMock.getCountry().getIsocode()).thenReturn(COUNTRY_ISO_CODE); testObj.populateAddressForm(addressDataMock, addressFormMock); verify(addressFormMock).setTitleCode(TITLE); verify(addressFormMock).setFirstName(FIRST_NAME); verify(addressFormMock).setLastName(LAST_NAME); verify(addressFormMock).setLine1(LINE_1); verify(addressFormMock).setLine2(LINE_2); verify(addressFormMock).setTownCity(TOWN); verify(addressFormMock).setPostcode(POSTAL_CODE); verify(addressFormMock).setCountryIso(COUNTRY_ISO_CODE); verify(addressFormMock).setPhone(PHONE_NUMBER); verify(addressFormMock).setRegionIso(REGION_ISO_CODE); }