public void notConvertible() { FxRateScenarioArray rates = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); List<String> values = ImmutableList.of("a", "b", "c"); DefaultScenarioArray<String> test = DefaultScenarioArray.of(values); ScenarioArray<?> convertedList = test.convertedTo(Currency.GBP, fxProvider); assertThat(convertedList).isEqualTo(test); }
public void noConversionNecessary() { FxRateScenarioArray rates = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); List<CurrencyAmount> values = ImmutableList.of( CurrencyAmount.of(Currency.GBP, 1), CurrencyAmount.of(Currency.GBP, 2), CurrencyAmount.of(Currency.GBP, 3)); DefaultScenarioArray<CurrencyAmount> test = DefaultScenarioArray.of(values); ScenarioArray<?> convertedList = test.convertedTo(Currency.GBP, fxProvider); ScenarioArray<CurrencyAmount> expectedList = DefaultScenarioArray.of(values); assertThat(convertedList).isEqualTo(expectedList); }
public void wrongNumberOfFxRates() { FxRateScenarioArray rates = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); List<CurrencyAmount> values = ImmutableList.of( CurrencyAmount.of(Currency.GBP, 1), CurrencyAmount.of(Currency.GBP, 2)); DefaultScenarioArray<CurrencyAmount> test = DefaultScenarioArray.of(values); assertThrows( () -> test.convertedTo(Currency.USD, fxProvider), IllegalArgumentException.class, "Expected 2 FX rates but received 3"); }
public void convertCurrencyAmount() { FxRateScenarioArray rates = FxRateScenarioArray.of(GBP, USD, DoubleArray.of(1.61, 1.62, 1.63)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); List<CurrencyAmount> values = ImmutableList.of( CurrencyAmount.of(Currency.GBP, 1), CurrencyAmount.of(Currency.GBP, 2), CurrencyAmount.of(Currency.GBP, 3)); DefaultScenarioArray<CurrencyAmount> test = DefaultScenarioArray.of(values); ScenarioArray<?> convertedList = test.convertedTo(Currency.USD, fxProvider); List<CurrencyAmount> expectedValues = ImmutableList.of( CurrencyAmount.of(Currency.USD, 1 * 1.61), CurrencyAmount.of(Currency.USD, 2 * 1.62), CurrencyAmount.of(Currency.USD, 3 * 1.63)); DefaultScenarioArray<CurrencyAmount> expectedList = DefaultScenarioArray.of(expectedValues); assertThat(convertedList).isEqualTo(expectedList); }
public void missingFxRates() { FxRateScenarioArray rates = FxRateScenarioArray.of(EUR, USD, DoubleArray.of(1.61, 1.62, 1.63)); ScenarioFxRateProvider fxProvider = new TestScenarioFxRateProvider(rates); List<CurrencyAmount> values = ImmutableList.of( CurrencyAmount.of(Currency.GBP, 1), CurrencyAmount.of(Currency.GBP, 2), CurrencyAmount.of(Currency.GBP, 3)); DefaultScenarioArray<CurrencyAmount> test = DefaultScenarioArray.of(values); assertThrows(() -> test.convertedTo(Currency.USD, fxProvider), IllegalArgumentException.class); }