use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.
the class StreamFactory method currencies.
public static Stream<MonetaryAmount> currencies() {
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 e1 = Money.of(BigDecimal.TEN, EURO);
Money e2 = Money.of(BigDecimal.ZERO, EURO);
Money e3 = Money.of(BigDecimal.ONE, EURO);
Money d1 = Money.of(BigDecimal.TEN, DOLLAR);
Money d2 = Money.of(BigDecimal.ZERO, DOLLAR);
Money d3 = Money.of(BigDecimal.ONE, DOLLAR);
return Stream.of(r1, r2, r3, e1, e2, e3, d1, d2, d3);
}
use of org.javamoney.moneta.Money in project jsr354-ri-bp by JavaMoney.
the class CurrencyProviderTest method testProviderComparison.
@Test
public void testProviderComparison() {
ExchangeRateProvider ecbRateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
ExchangeRateProvider imfRateProvider = MonetaryConversions.getExchangeRateProvider("IMF");
CurrencyConversion ecbDollarConversion = ecbRateProvider.getCurrencyConversion("USD");
CurrencyConversion imfDollarConversion = imfRateProvider.getCurrencyConversion("USD");
try {
// Wait for IMF provider to load
Thread.sleep(10000L);
for (String currency : new String[] { "INR", "CHF", "BRL" }) {
Money money = Money.of(2, currency);
System.out.println("ECB : " + money.with(ecbDollarConversion));
System.out.println("IMF : " + money.with(imfDollarConversion));
assertEquals("Too much difference (ECB/IMF) for " + money, money.with(ecbDollarConversion).getNumber().doubleValue(), money.with(imfDollarConversion).getNumber().doubleValue(), 0.4d);
}
} catch (Exception e) {
// This test may fail, if the network is slow or not available, so only write the exception as of now...
e.printStackTrace();
}
}
use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.
the class StreamFactory method streamNull.
public static Stream<MonetaryAmount> streamNull() {
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), BRAZILIAN_REAL);
Money m5 = Money.of(BigDecimal.valueOf(5L), BRAZILIAN_REAL);
return Stream.of(m1, m2, m3, m4, m5, null);
}
use of org.javamoney.moneta.Money in project jsr354-ri by JavaMoney.
the class StreamFactory method streamNormal.
public static Stream<MonetaryAmount> streamNormal() {
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), BRAZILIAN_REAL);
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 MonetaryAmountFormatTest method testWithCustomPattern.
/**
* Test related to {@link https://java.net/jira/browse/JAVAMONEY-92}.
*/
@Test
public void testWithCustomPattern() {
MonetaryAmountFormat format = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(Locale.GERMANY).set(CurrencyStyle.SYMBOL).set("pattern", "#,##0.00### ¤").build());
Money money = Money.of(12345.23456789, "EUR");
assertEquals("12.345,23457 €", format.format(money));
format = MonetaryFormats.getAmountFormat(AmountFormatQueryBuilder.of(Locale.GERMANY).set(CurrencyStyle.SYMBOL).build());
assertEquals("12.345,23 €", format.format(money));
}
Aggregations