Search in sources :

Example 1 with CurrencyConversion

use of javax.money.convert.CurrencyConversion in project tutorials by eugenp.

the class JavaMoneyUnitManualTest method givenAmount_whenConversion_thenNotNull.

@Test
@Ignore("Currency providers are not always available")
public void givenAmount_whenConversion_thenNotNull() {
    MonetaryAmount oneDollar = Monetary.getDefaultAmountFactory().setCurrency("USD").setNumber(1).create();
    CurrencyConversion conversionEUR = MonetaryConversions.getConversion("EUR");
    MonetaryAmount convertedAmountUSDtoEUR = oneDollar.with(conversionEUR);
    assertEquals("USD 1", oneDollar.toString());
    assertNotNull(convertedAmountUSDtoEUR);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with CurrencyConversion

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

the class ExchangeRateMonetarySummaryStatistics method to.

@Override
public MonetarySummaryStatistics to(CurrencyUnit unit) {
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(unit);
    ExchangeRateMonetarySummaryStatistics another = new ExchangeRateMonetarySummaryStatistics(unit, provider);
    another.average = currencyConversion.apply(average);
    another.count = count;
    another.max = currencyConversion.apply(max);
    another.min = currencyConversion.apply(min);
    another.sum = currencyConversion.apply(sum);
    return another;
}
Also used : CurrencyConversion(javax.money.convert.CurrencyConversion)

Example 3 with CurrencyConversion

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

the class ECBHistoricRateProviderTest 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);
}
Also used : MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 4 with CurrencyConversion

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

the class ECBHistoricRateProviderTest 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 5 with CurrencyConversion

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

the class ECBHistoricRateProviderTest method shouldConvertsDollarToBrazilian.

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

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