Search in sources :

Example 16 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class IMFHistoricRateProviderTest method shouldConvertsDollarToEuro.

@Test
public void shouldConvertsDollarToEuro() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(EURO);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    MonetaryAmount result = currencyConversion.apply(money);
    assertEquals(result.getCurrency(), EURO);
    assertTrue(result.getNumber().doubleValue() > 0);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 17 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class ProviderTest method testAccess_ECB.

@Test
public void testAccess_ECB() throws InterruptedException {
    final MonetaryAmount inEuro = Money.of(10, "EUR");
    for (int i = 0; i < 100; i++) {
        try {
            final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
            final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
            final MonetaryAmount inDollar = inEuro.with(dollarConversion);
            System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    for (int i = 0; i < 100; i++) {
        final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB");
        final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
        Thread.sleep(100L);
        final MonetaryAmount inDollar = inEuro.with(dollarConversion);
        System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
    }
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) Test(org.testng.annotations.Test)

Example 18 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class ProviderTest method testAccess_HIST.

@Test
public void testAccess_HIST() throws InterruptedException {
    final MonetaryAmount inEuro = Money.of(10, "EUR");
    for (int i = 0; i < 100; i++) {
        try {
            final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST");
            final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
            final MonetaryAmount inDollar = inEuro.with(dollarConversion);
            System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    for (int i = 0; i < 100; i++) {
        final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST");
        final CurrencyConversion dollarConversion = rateProvider.getCurrencyConversion("USD");
        Thread.sleep(100L);
        final MonetaryAmount inDollar = inEuro.with(dollarConversion);
        System.out.println(String.format("RUN: %n - %s: %s ≙ %s", i, rateProvider, inEuro, inDollar));
    }
}
Also used : ExchangeRateProvider(javax.money.convert.ExchangeRateProvider) MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) Test(org.testng.annotations.Test)

Example 19 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class ConversionAggregatorTest method shouldSumExchangeCorrectly.

@Test
public void shouldSumExchangeCorrectly() {
    Stream<MonetaryAmount> stream = currencies();
    MonetaryAmount sum = stream.reduce(sum(provider, DOLLAR)).get();
    Assert.assertTrue(sum.getNumber().intValue() > 20);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Example 20 with MonetaryAmount

use of javax.money.MonetaryAmount in project jsr354-ri by JavaMoney.

the class ConversionOperatorsTest method shouldExchangeCurrencyNegativeValue.

@Test
public void shouldExchangeCurrencyNegativeValue() {
    CurrencyUnit real = Monetary.getCurrency("BRL");
    MonetaryAmount money = Money.parse("BHD -1.345");
    MonetaryAmount result = ConversionOperators.exchange(real).apply(money);
    assertNotNull(result);
    assertEquals(result.getCurrency(), real);
    assertEquals(Double.valueOf(-1.345), result.getNumber().doubleValue());
}
Also used : CurrencyUnit(javax.money.CurrencyUnit) MonetaryAmount(javax.money.MonetaryAmount) Test(org.testng.annotations.Test)

Aggregations

MonetaryAmount (javax.money.MonetaryAmount)275 Test (org.testng.annotations.Test)260 CurrencyConversion (javax.money.convert.CurrencyConversion)88 BeforeTest (org.testng.annotations.BeforeTest)83 BigDecimal (java.math.BigDecimal)64 CurrencyUnit (javax.money.CurrencyUnit)57 ConversionQuery (javax.money.convert.ConversionQuery)10 RoundedMoney (org.javamoney.moneta.RoundedMoney)10 LocalDate (java.time.LocalDate)9 ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)9 Test (org.junit.Test)9 FastMoney (org.javamoney.moneta.FastMoney)6 Money (org.javamoney.moneta.Money)6 MathContext (java.math.MathContext)4 MonetaryOperator (javax.money.MonetaryOperator)4 MonetaryAmountFormat (javax.money.format.MonetaryAmountFormat)4 MonetaryAmountFactory (javax.money.MonetaryAmountFactory)3 BookingBean (com.github.drbookings.model.data.BookingBean)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2