APMAvailabilityCurrencyStrategy implements APMAvailabilityStrategy { @Override public boolean isAvailable(final WorldpayAPMConfigurationModel apmConfiguration, final CartModel cartModel) { if (CollectionUtils.isEmpty(apmConfiguration.getCurrencies())) { return true; } final String cartCurrencyIso = cartModel.getCurrency().getIsocode(); return apmConfiguration.getCurrencies().stream() .map(C2LItemModel::getIsocode) .anyMatch(cartCurrencyIso::equals); }  @Override boolean isAvailable(final WorldpayAPMConfigurationModel apmConfiguration, final CartModel cartModel);  }
@Test public void isAvailableReturnsTrueWhenNoCurrenciesSpecifiedInConfiguration() { when(apmConfigurationMock.getCurrencies()).thenReturn(Collections.emptySet()); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertTrue(result); }
@Test public void isAvailableReturnsTrueWhenCurrencyListIsNullInConfiguration() { when(apmConfigurationMock.getCurrencies()).thenReturn(null); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertTrue(result); }
@Test public void isAvailableReturnsFalseWhenCartCurrencyIsNotSpecifiedInConfiguration() { final HashSet<CurrencyModel> currencyModels = new HashSet<>(); currencyModels.add(currencyModelGBPMock); when(apmConfigurationMock.getCurrencies()).thenReturn(currencyModels); when(currencyModelGBPMock.getIsocode()).thenReturn(Currency.getInstance(UK).getCurrencyCode()); when(cartModelMock.getCurrency().getIsocode()).thenReturn(Currency.getInstance(ITALY).getCurrencyCode()); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertFalse(result); }
@Test public void isAvailableReturnsTrueWhenCountrySpecifiedInConfiguration() { final HashSet<CurrencyModel> currencyModels = new HashSet<>(); currencyModels.add(currencyModelGBPMock); when(apmConfigurationMock.getCurrencies()).thenReturn(currencyModels); when(currencyModelGBPMock.getIsocode()).thenReturn(Currency.getInstance(UK).getCurrencyCode()); when(cartModelMock.getCurrency().getIsocode()).thenReturn(Currency.getInstance(UK).getCurrencyCode()); final boolean result = testObj.isAvailable(apmConfigurationMock, cartModelMock); assertTrue(result); }