Search in sources :

Example 16 with Money

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);
}
Also used : Money(org.javamoney.moneta.Money)

Example 17 with Money

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();
    }
}
Also used : Money(org.javamoney.moneta.Money) ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) CurrencyConversion(javax.money.convert.CurrencyConversion) Test(org.testng.annotations.Test)

Example 18 with Money

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);
}
Also used : Money(org.javamoney.moneta.Money)

Example 19 with Money

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);
}
Also used : Money(org.javamoney.moneta.Money)

Example 20 with Money

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));
}
Also used : Money(org.javamoney.moneta.Money) MonetaryAmountFormat(javax.money.format.MonetaryAmountFormat) Test(org.testng.annotations.Test)

Aggregations

Money (org.javamoney.moneta.Money)31 AttributeMoney (life.genny.qwanda.attribute.AttributeMoney)7 CurrencyUnit (javax.money.CurrencyUnit)4 MonetaryAmount (javax.money.MonetaryAmount)4 FastMoney (org.javamoney.moneta.FastMoney)4 Test (org.junit.Test)4 BaseEntity (life.genny.qwanda.entity.BaseEntity)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Scanner (java.util.Scanner)2 Answer (life.genny.qwanda.Answer)2 QRules (life.genny.rules.QRules)2 Test (org.testng.annotations.Test)2 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CurrencyConversion (javax.money.convert.CurrencyConversion)1 ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)1 MonetaryAmountFormat (javax.money.format.MonetaryAmountFormat)1 AttributeBoolean (life.genny.qwanda.attribute.AttributeBoolean)1