Search in sources :

Example 56 with CurrencyConversion

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

the class ECBHistoric90RateProviderTest 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 57 with CurrencyConversion

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

the class ECBHistoric90RateProviderTest method shouldReturnsSameDollarValue.

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

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

the class ECBHistoric90RateProviderTest method shouldReturnErrorWhenDoesNotFindTheExchangeRate.

@Test(expectedExceptions = MonetaryException.class)
public void shouldReturnErrorWhenDoesNotFindTheExchangeRate() {
    LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9);
    ConversionQuery conversionQuery = ConversionQueryBuilder.of().set(localDate).setTermCurrency(EURO).build();
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(conversionQuery);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    currencyConversion.apply(money);
    fail();
}
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 59 with CurrencyConversion

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

the class ECBHistoric90RateProviderTest method shouldReturnErrorWhenFindFromHistoricalUsingPeriod.

@Test(expectedExceptions = MonetaryException.class)
public void shouldReturnErrorWhenFindFromHistoricalUsingPeriod() {
    LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9);
    ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(EURO).set(withDaysBetween(localDate.minusDays(1), localDate)).build();
    CurrencyConversion currencyConversion = provider.getCurrencyConversion(conversionQuery);
    assertNotNull(currencyConversion);
    MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
    currencyConversion.apply(money);
    fail();
}
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 60 with CurrencyConversion

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

the class ECBHistoric90RateProviderTest 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