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);
}
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));
}
}
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));
}
}
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);
}
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());
}
Aggregations