Search in sources :

Example 6 with ConversionQuery

use of javax.money.convert.ConversionQuery 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 7 with ConversionQuery

use of javax.money.convert.ConversionQuery 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 8 with ConversionQuery

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

the class ECBHistoric90RateProviderTest method shouldSetTimeInLocalDateTime.

@Test(expectedExceptions = MonetaryException.class)
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 9 with ConversionQuery

use of javax.money.convert.ConversionQuery 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 10 with ConversionQuery

use of javax.money.convert.ConversionQuery 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)

Aggregations

ConversionQuery (javax.money.convert.ConversionQuery)11 MonetaryAmount (javax.money.MonetaryAmount)10 CurrencyConversion (javax.money.convert.CurrencyConversion)10 BeforeTest (org.testng.annotations.BeforeTest)10 Test (org.testng.annotations.Test)10 LocalDate (java.time.LocalDate)9 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 InputStream (java.io.InputStream)1 MathContext (java.math.MathContext)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Comparator (java.util.Comparator)1 Map (java.util.Map)1 Objects (java.util.Objects)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 TimeUnit (java.util.concurrent.TimeUnit)1 Level (java.util.logging.Level)1 Logger (java.util.logging.Logger)1 Collectors (java.util.stream.Collectors)1