GooglePayController extends AbstractCheckoutController { protected void setRegion(final AddressData addressData, final GooglePayAddressData address) { final String administrativeArea = address.getAdministrativeArea(); if (StringUtils.isEmpty(administrativeArea)) { return; } final String countryIsoCode = address.getCountryCode(); final RegionData region = i18NFacade.getRegion(countryIsoCode, administrativeArea); if (region != null) { addressData.setRegion(region); } else { LOG.debug(MessageFormat.format("Failed to determine region from country {0} and region code {1}", countryIsoCode, administrativeArea)); } }  @RequireHardLogIn @PostMapping(value = "/authorise-order", consumes = {MediaType.APPLICATION_JSON_VALUE}) DirectResponseData authoriseOrder(@RequestBody final GooglePayAuthorisationRequest authorisationRequest);  }
@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 GooglePayAddressData address = new GooglePayAddressData(); 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)).thenReturn(null); final GooglePayAddressData address = new GooglePayAddressData(); address.setCountryCode(countryCode); address.setAdministrativeArea(regionCode); final AddressData addressData = mock(AddressData.class); testObj.setRegion(addressData, address); verifyZeroInteractions(addressData); }