public void convertedTo() { SwapLegAmount legAmount = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.GBP, 10)) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.GBP) .build(); SwapLegAmount convertedAmount = legAmount.convertedTo(Currency.USD, FxRate.of(Currency.GBP, Currency.USD, 1.6)); assertThat(convertedAmount.getAmount().getCurrency()).isEqualTo(Currency.USD); assertThat(convertedAmount.getAmount().getAmount()).isEqualTo(16.0); assertThat(convertedAmount.getPayReceive()).isEqualTo(legAmount.getPayReceive()); assertThat(convertedAmount.getType()).isEqualTo(legAmount.getType()); assertThat(convertedAmount.getCurrency()).isEqualTo(legAmount.getCurrency()); }
/** * Tests evaluating a bean with a single property. There are 2 different expected behaviours: * * 1) If the token matches the property, the property value is returned and the token is consumed. This is the same * as the normal bean behaviour. * 2) If the token doesn't match the property it is assumed to match something on the property's value. In this * case the property value is returned and no tokens are consumed. */ public void evaluateSingleProperty() { SwapLegAmount amount = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.AUD, 7)) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.AUD) .build(); LegAmounts amounts = LegAmounts.of(amount); BeanTokenEvaluator evaluator = new BeanTokenEvaluator(); EvaluationResult result1 = evaluator.evaluate(amounts, FUNCTIONS, "amounts", ImmutableList.of("foo", "bar")); assertThat(result1.getResult()).hasValue(ImmutableList.of(amount)); assertThat(result1.getRemainingTokens()).isEqualTo(ImmutableList.of("foo", "bar")); EvaluationResult result2 = evaluator.evaluate(amounts, FUNCTIONS, "baz", ImmutableList.of("foo", "bar")); assertThat(result2.getResult()).hasValue(ImmutableList.of(amount)); assertThat(result2.getRemainingTokens()).isEqualTo(ImmutableList.of("baz", "foo", "bar")); }
/** * Tests the tokens() method when the bean has a single property. The tokens should include the single property * name plus the tokens of the property value. */ public void tokensSingleProperty() { SwapLegAmount amount = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.AUD, 7)) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.AUD) .build(); LegAmounts amounts = LegAmounts.of(amount); BeanTokenEvaluator evaluator = new BeanTokenEvaluator(); Set<String> tokens = evaluator.tokens(amounts); assertThat(tokens).isEqualTo(ImmutableSet.of("amounts", "0", "aud", "pay", "fixed")); }
public void coverage() { SwapLegAmount la1 = SwapLegAmount.builder() .amount(CURRENCY_AMOUNT) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.EUR) .build(); coverImmutableBean(la1); SwapLegAmount la2 = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.GBP, 10000)) .payReceive(PayReceive.RECEIVE) .type(SwapLegType.IBOR) .currency(Currency.GBP) .build(); coverBeanEquals(la1, la2); }
/** * Obtains an instance from a swap leg and amount. * * @param leg the swap leg * @param amount the amount * @return the swap leg amount */ public static SwapLegAmount of(ResolvedSwapLeg leg, CurrencyAmount amount) { return builder() .amount(amount) .payReceive(leg.getPayReceive()) .type(leg.getType()) .currency(leg.getCurrency()) .build(); }
public void coverage() { LegAmounts test1 = LegAmounts.of(LEG_AMOUNT_1, LEG_AMOUNT_2); coverImmutableBean(test1); LegAmount swapLeg = SwapLegAmount.builder() .amount(CurrencyAmount.of(Currency.GBP, 1557.445)) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.EUR) .build(); LegAmounts test2 = LegAmounts.of(swapLeg); coverBeanEquals(test1, test2); }
public void test_serialization() { SwapLegAmount la = SwapLegAmount.builder() .amount(CURRENCY_AMOUNT) .payReceive(PayReceive.PAY) .type(SwapLegType.FIXED) .currency(Currency.EUR) .build(); assertSerialization(la); }