Search in sources :

Example 66 with CurrencyConversion

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

the class IMFHistoricRateProviderTest method shouldSetTimeInLocalDateTime.

@Test
public void shouldSetTimeInLocalDateTime() {
    LocalDate localDate = YearMonth.of(2014, Month.JANUARY).atDay(9);
    ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(EURO).set(localDate).build();
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(conversionQuery);
    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 : ConversionQuery(javax.money.convert.ConversionQuery) MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 67 with CurrencyConversion

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

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

Example 68 with CurrencyConversion

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

the class IMFHistoricRateProviderTest method shouldSetTimeInLocalDateTime2.

@Test
public void shouldSetTimeInLocalDateTime2() {
    LocalDate localDate = LocalDate.now().minusDays(90).with(TemporalAdjusters.next(DayOfWeek.FRIDAY));
    ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(EURO).set(localDate).build();
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(conversionQuery);
    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 : ConversionQuery(javax.money.convert.ConversionQuery) MonetaryAmount(javax.money.MonetaryAmount) CurrencyConversion(javax.money.convert.CurrencyConversion) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 69 with CurrencyConversion

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

the class IMFHistoricRateProviderTest 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 70 with CurrencyConversion

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

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

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