APMAvailabilityCountryStrategy implements APMAvailabilityStrategy { @Override public boolean isAvailable(final WorldpayAPMConfigurationModel apmConfiguration, final CartModel cartModel) { if (CollectionUtils.isEmpty(apmConfiguration.getCountries())) { return true; } final String shippingCountryIsoCode = worldpayDeliveryAddressStrategy.getDeliveryAddress(cartModel).getCountry().getIsocode(); return apmConfiguration.getCountries().stream() .map(C2LItemModel::getIsocode) .anyMatch(shippingCountryIsoCode::equals); }  @Override boolean isAvailable(final WorldpayAPMConfigurationModel apmConfiguration, final CartModel cartModel); @Required void setWorldpayDeliveryAddressStrategy(final WorldpayDeliveryAddressStrategy worldpayDeliveryAddressStrategy);  }
@Test public void isAvailableReturnsTrueWhenNoCountriesSpecifiedInConfiguration() { when(apmConfigurationMock.getCountries()).thenReturn(Collections.emptySet()); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertTrue(result); }
@Test public void isAvailableReturnsTrueWhenCountryListIsNullInConfiguration() { when(apmConfigurationMock.getCountries()).thenReturn(null); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertTrue(result); }
@Test public void isAvailableReturnsFalseWhenCountryNotSpecifiedInConfiguration() { final HashSet<CountryModel> countryModels = new HashSet<>(); countryModels.add(countryModelUkMock); when(countryModelUkMock.getIsocode()).thenReturn(Locale.UK.getCountry()); when(apmConfigurationMock.getCountries()).thenReturn(countryModels); when(worldpayDeliveryAddressStrategyMock.getDeliveryAddress(cartModelMock)).thenReturn(deliveryAddressModelMock); when(deliveryAddressModelMock.getCountry().getIsocode()).thenReturn(ITALY.getCountry()); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertFalse(result); }
@Test public void isAvailableReturnsTrueWhenCountrySpecifiedInConfiguration() { final HashSet<CountryModel> countryModels = new HashSet<>(); countryModels.add(countryModelUkMock); when(apmConfigurationMock.getCountries()).thenReturn(countryModels); when(countryModelUkMock.getIsocode()).thenReturn(Locale.UK.getCountry()); when(worldpayDeliveryAddressStrategyMock.getDeliveryAddress(cartModelMock)).thenReturn(deliveryAddressModelMock); when(deliveryAddressModelMock.getCountry().getIsocode()).thenReturn(Locale.UK.getCountry()); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertTrue(result); }