use of javax.money.convert.CurrencyConversion in project jsr354-ri by JavaMoney.
the class ECBCurrentRateProviderTest 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);
}
use of javax.money.convert.CurrencyConversion in project jsr354-ri by JavaMoney.
the class ECBCurrentRateProviderTest method shouldConvertsEuroToDollar.
@Test
public void shouldConvertsEuroToDollar() {
CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, EURO);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), DOLLAR);
assertTrue(result.getNumber().doubleValue() > 0);
}
use of javax.money.convert.CurrencyConversion 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 javax.money.convert.CurrencyConversion in project jsr354-ri-bp by JavaMoney.
the class ECBEarlyAccessProviderTest method testAccess_HIST90.
@Test
public void testAccess_HIST90() throws InterruptedException {
final MonetaryAmount inEuro = Money.of(10, "EUR");
for (int i = 0; i < 100; i++) {
try {
final ExchangeRateProvider rateProvider = MonetaryConversions.getExchangeRateProvider("ECB-HIST90");
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-HIST90");
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));
}
}
use of javax.money.convert.CurrencyConversion in project jsr354-ri-bp 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);
}
Aggregations