/** * Assert that the {@code CurrencyAmount} has the same currency as * the supplied {@code CurrencyAmount} and that the amount is within * range of the supplied {@code CurrencyAmount}'s amount. * * @param expected the expected {@code CurrencyAmount} * @param tolerance the tolerance to use * @return this if the amount matches the expectation, else * throw an {@code AssertionError} */ public CurrencyAmountAssert isEqualTo(CurrencyAmount expected, Offset<Double> tolerance) { isNotNull(); hasCurrency(expected.getCurrency()); hasAmount(expected.getAmount(), tolerance); return this; }
public void convertMultipleCurrencyAmountWithNoEntries() { FxMatrix matrix = FxMatrix.builder() .addRate(GBP, EUR, 1.4) .addRate(GBP, USD, 1.6) .build(); MultiCurrencyAmount amount = MultiCurrencyAmount.of(); assertThat(matrix.convert(amount, GBP)) .hasCurrency(GBP) .hasAmount(0); assertThat(matrix.convert(amount, USD)) .hasCurrency(USD) .hasAmount(0); assertThat(matrix.convert(amount, EUR)) .hasCurrency(EUR) .hasAmount(0); }
public void convertMultipleCurrencyAmountWithSingleEntry() { FxMatrix matrix = FxMatrix.builder() .addRate(GBP, EUR, 1.4) .addRate(GBP, USD, 1.6) .build(); MultiCurrencyAmount amount = MultiCurrencyAmount.of(CurrencyAmount.of(GBP, 1600)); assertThat(matrix.convert(amount, GBP)) .hasCurrency(GBP) .hasAmount(1600); assertThat(matrix.convert(amount, USD)) .hasCurrency(USD) .hasAmount(2560); assertThat(matrix.convert(amount, EUR)) .hasCurrency(EUR) .hasAmount(2240); }
public void convertMultipleCurrencyAmountWithMultipleEntries() { FxMatrix matrix = FxMatrix.builder() .addRate(GBP, EUR, 1.4) .addRate(GBP, USD, 1.6) .build(); MultiCurrencyAmount amount = MultiCurrencyAmount.of( CurrencyAmount.of(GBP, 1600), CurrencyAmount.of(EUR, 1200), CurrencyAmount.of(USD, 1500)); assertThat(matrix.convert(amount, GBP)) .hasCurrency(GBP) .hasAmount(1600d + (1200 / 1.4) + (1500 / 1.6), TOL); assertThat(matrix.convert(amount, USD)) .hasCurrency(USD) .hasAmount((1600d * 1.6) + ((1200 / 1.4) * 1.6) + 1500); assertThat(matrix.convert(amount, EUR)) .hasCurrency(EUR) .hasAmount((1600d * 1.4) + 1200 + ((1500 / 1.6) * 1.4)); }
public void convertCurrencyAmount() { FxMatrix matrix = FxMatrix.builder() .addRate(GBP, EUR, 1.4) .addRate(GBP, USD, 1.6) .build(); CurrencyAmount amount = CurrencyAmount.of(GBP, 1600); assertThat(matrix.convert(amount, GBP)).isEqualTo(amount); assertThat(matrix.convert(amount, USD)) .hasCurrency(USD) .hasAmount(2560); assertThat(matrix.convert(amount, EUR)) .hasCurrency(EUR) .hasAmount(2240); }
public void test_ofForecastValue_Currency() { CashFlow test = CashFlow.ofForecastValue(PAYMENT_DATE, GBP, FORECAST_VALUE, DISCOUNT_FACTOR); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_ofPresentValue_CurrencyAmount() { CashFlow test = CashFlow.ofPresentValue(PAYMENT_DATE, PRESENT_AMOUNT, DISCOUNT_FACTOR); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_ofForecastValue_CurrencyAmount() { CashFlow test = CashFlow.ofForecastValue(PAYMENT_DATE, FUTURE_AMOUNT, DISCOUNT_FACTOR); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_ofPresentValue_Currency() { CashFlow test = CashFlow.ofPresentValue(PAYMENT_DATE, GBP, PRESENT_VALUE, DISCOUNT_FACTOR); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_convertedTo() { CashFlow base = CashFlow.ofForecastValue(PAYMENT_DATE, GBP, FORECAST_VALUE, DISCOUNT_FACTOR); CashFlow test = base.convertedTo(USD, FxRate.of(GBP, USD, 1.5)); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(USD); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE * 1.5, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(USD); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE * 1.5, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }
public void test_convertedTo_noConversion() { CashFlow base = CashFlow.ofForecastValue(PAYMENT_DATE, GBP, FORECAST_VALUE, DISCOUNT_FACTOR); CashFlow test = base.convertedTo(GBP, FxMatrix.empty()); assertThat(test.getPaymentDate()).isEqualTo(PAYMENT_DATE); assertThat(test.getPresentValue()).hasCurrency(GBP); assertThat(test.getPresentValue()).hasAmount(PRESENT_VALUE, TOLERANCE); assertThat(test.getForecastValue()).hasCurrency(GBP); assertThat(test.getForecastValue()).hasAmount(FORECAST_VALUE, TOLERANCE); assertThat(test.getDiscountFactor()).isCloseTo(DISCOUNT_FACTOR, TOLERANCE); }