use of org.javamoney.moneta.Money in project tutorials by eugenp.
the class JavaMoneyUnitManualTest method givenArithmetic_whenStringified_thanEqualsAmount.
@Test
public void givenArithmetic_whenStringified_thanEqualsAmount() {
CurrencyUnit usd = Monetary.getCurrency("USD");
Money moneyof = Money.of(12, usd);
MonetaryAmount fstAmtUSD = Monetary.getDefaultAmountFactory().setCurrency(usd).setNumber(200.50).create();
MonetaryAmount oneDolar = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(1).create();
Money subtractedAmount = Money.of(1, "USD").subtract(fstAmtUSD);
MonetaryAmount multiplyAmount = oneDolar.multiply(0.25);
MonetaryAmount divideAmount = oneDolar.divide(0.25);
assertEquals("USD", usd.toString());
assertEquals("USD 1", oneDolar.toString());
assertEquals("USD 200.5", fstAmtUSD.toString());
assertEquals("USD 12", moneyof.toString());
assertEquals("USD -199.5", subtractedAmount.toString());
assertEquals("USD 0.25", multiplyAmount.toString());
assertEquals("USD 4", divideAmount.toString());
}
use of org.javamoney.moneta.Money in project tutorials by eugenp.
the class JavaMoneyUnitManualTest method givenAmounts_whenSummed_thanCorrect.
@Test
public void givenAmounts_whenSummed_thanCorrect() {
List<MonetaryAmount> monetaryAmounts = Arrays.asList(Money.of(100, "CHF"), Money.of(10.20, "CHF"), Money.of(1.15, "CHF"));
Money sumAmtCHF = (Money) monetaryAmounts.stream().reduce(Money.of(0, "CHF"), MonetaryAmount::add);
assertEquals("CHF 111.35", sumAmtCHF.toString());
}
use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.
the class StreamFactory method currenciesToSummary.
public static Stream<MonetaryAmount> currenciesToSummary() {
Money r1 = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
Money r2 = Money.of(BigDecimal.ZERO, BRAZILIAN_REAL);
Money r3 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r4 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r5 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r6 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r7 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r8 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money e1 = Money.of(BigDecimal.TEN, EURO);
Money d1 = Money.of(BigDecimal.ONE, DOLLAR);
return Stream.of(r1, r2, r3, r4, r5, r6, r7, r8, e1, d1);
}
use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.
the class StreamFactory method streamCurrencyDifferent.
public static Stream<MonetaryAmount> streamCurrencyDifferent() {
Money m1 = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
Money m2 = Money.of(BigDecimal.ZERO, BRAZILIAN_REAL);
Money m3 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money m4 = Money.of(BigDecimal.valueOf(4L), EURO);
Money m5 = Money.of(BigDecimal.valueOf(5L), BRAZILIAN_REAL);
return Stream.of(m1, m2, m3, m4, m5);
}
use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.
the class StreamFactory method currenciesToSummary.
public static Stream<MonetaryAmount> currenciesToSummary() {
Money r1 = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
Money r2 = Money.of(BigDecimal.ZERO, BRAZILIAN_REAL);
Money r3 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r4 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r5 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r6 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r7 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money r8 = Money.of(BigDecimal.ONE, BRAZILIAN_REAL);
Money e1 = Money.of(BigDecimal.TEN, EURO);
Money d1 = Money.of(BigDecimal.ONE, DOLLAR);
return Stream.of(r1, r2, r3, r4, r5, r6, r7, r8, e1, d1);
}
Aggregations