DefaultWorldpayApplePayPaymentCheckoutFacade implements WorldpayApplePayPaymentCheckoutFacade { @Override public void setRegion(final AddressData addressData, final ApplePayPaymentContact address) { final String administrativeArea = address.getAdministrativeArea(); if (StringUtils.isNotEmpty(administrativeArea)) { final String countryIsoCode = address.getCountryCode(); try { addressData.setRegion(i18NFacade.getRegion(countryIsoCode, administrativeArea)); } catch (final UnknownIdentifierException e) { LOG.debug("Failed to determine region from country {} and region code {}", countryIsoCode, administrativeArea, e); } } }  @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 testSetRegion() { final AddressData addressData = mock(AddressData.class); final RegionData region = mock(RegionData.class); final String countryCode = "US"; final String regionCode = "CA"; when(i18NFacadeMock.getRegion(countryCode, regionCode)).thenReturn(region); final ApplePayPaymentContact address = new ApplePayPaymentContact(); address.setCountryCode(countryCode); address.setAdministrativeArea(regionCode); testObj.setRegion(addressData, address); verify(addressData).setRegion(region); }
@Test public void testSetRegionNotFound() { final String countryCode = "ES"; final String regionCode = "Valencia"; when(i18NFacadeMock.getRegion(countryCode, regionCode)).thenThrow(new UnknownIdentifierException("region not found")); final ApplePayPaymentContact address = new ApplePayPaymentContact(); address.setCountryCode(countryCode); address.setAdministrativeArea(regionCode); final AddressData addressData = mock(AddressData.class); testObj.setRegion(addressData, address); verifyZeroInteractions(addressData); }