Search in sources :

Example 71 with CurrencyConversion

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

the class IMFHistoricRateProviderTest method shouldConvertsBrazilianToDollar.

@Test
public void shouldConvertsBrazilianToDollar() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    MonetaryAmount result = currencyConversion.apply(money);
    assertEquals(result.getCurrency(), DOLLAR);
    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 72 with CurrencyConversion

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

the class ECBCurrentRateProviderTest method shouldReturnsSameBrazilianValue.

@Test
public void shouldReturnsSameBrazilianValue() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(BRAZILIAN_REAL);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
    MonetaryAmount result = currencyConversion.apply(money);
    assertEquals(result.getCurrency(), BRAZILIAN_REAL);
    assertEquals(result.getNumber().numberValue(BigDecimal.class), BigDecimal.TEN);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 73 with CurrencyConversion

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

the class ECBCurrentRateProviderTest method shouldReturnsSameEuroValue.

@Test
public void shouldReturnsSameEuroValue() {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(EURO);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, EURO);
    MonetaryAmount result = currencyConversion.apply(money);
    assertEquals(result.getCurrency(), EURO);
    assertEquals(result.getNumber().numberValue(BigDecimal.class), BigDecimal.TEN);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) BigDecimal(java.math.BigDecimal) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 74 with CurrencyConversion

use of javax.money.convert.CurrencyConversion in project jsr354-ri-bp by JavaMoney.

the class ECBEarlyAccessProviderTest 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 75 with CurrencyConversion

use of javax.money.convert.CurrencyConversion in project jsr354-ri-bp by JavaMoney.

the class ECBEarlyAccessProviderTest 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)

Aggregations

CurrencyConversion (javax.money.convert.CurrencyConversion)91 MonetaryAmount (javax.money.MonetaryAmount)88 Test (org.testng.annotations.Test)88 BeforeTest (org.testng.annotations.BeforeTest)76 BigDecimal (java.math.BigDecimal)30 ConversionQuery (javax.money.convert.ConversionQuery)10 ExchangeRateProvider (javax.money.convert.ExchangeRateProvider)10 LocalDate (java.time.LocalDate)8 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 Money (org.javamoney.moneta.Money)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1