@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -879772901: // amounts return ((LegAmounts) bean).getAmounts(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public LegAmounts build() { return new LegAmounts( amounts); }
public void convertedTo() { LegAmounts base = LegAmounts.of(LEG_AMOUNT_1, LEG_AMOUNT_2); LegAmounts test = base.convertedTo(Currency.GBP, FxRate.of(Currency.USD, Currency.GBP, 0.7)); assertThat(test.getAmounts().get(0).getAmount().getCurrency()).isEqualTo(Currency.GBP); assertThat(test.getAmounts().get(0).getAmount().getAmount()).isEqualTo(500d * 0.7d); assertThat(test.getAmounts().get(1).getAmount().getCurrency()).isEqualTo(Currency.GBP); assertThat(test.getAmounts().get(1).getAmount().getAmount()).isEqualTo(420d * 0.7d); }
public void test_of_list() { List<LegAmount> list = ImmutableList.of(LEG_AMOUNT_1, LEG_AMOUNT_2); LegAmounts test = LegAmounts.of(list); assertEquals(test.getAmounts().size(), 2); assertEquals(test.getAmounts().get(0), LEG_AMOUNT_1); assertEquals(test.getAmounts().get(1), LEG_AMOUNT_2); }
@Override public LegAmounts convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { List<LegAmount> convertedAmounts = amounts.stream() .map(amount -> amount.convertedTo(resultCurrency, rateProvider)) .collect(toImmutableList()); return of(convertedAmounts); }
public void test_of_arrayAmounts() { LegAmounts test = LegAmounts.of(LEG_AMOUNT_1, LEG_AMOUNT_2); assertEquals(test.getAmounts().size(), 2); assertEquals(test.getAmounts().get(0), LEG_AMOUNT_1); assertEquals(test.getAmounts().get(1), LEG_AMOUNT_2); }
public void test_serialization() { LegAmounts test = LegAmounts.of(LEG_AMOUNT_1, LEG_AMOUNT_2); assertSerialization(test); }
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); }
/** * Returns an instance containing the specified leg amounts. * * @param amounts the individual leg amounts * @return an instance containing the specified leg amounts */ public static LegAmounts of(List<LegAmount> amounts) { return new LegAmounts(amounts); }
/** * 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")); }
/** * Returns an instance containing the specified leg amounts. * * @param amounts the individual leg amounts * @return an instance containing the specified leg amounts */ public static LegAmounts of(LegAmount... amounts) { return new LegAmounts(ImmutableList.copyOf(amounts)); }
/** * 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")); }