本文整理汇总了Java中javax.money.convert.CurrencyConversion.apply方法的典型用法代码示例。如果您正苦于以下问题:Java CurrencyConversion.apply方法的具体用法?Java CurrencyConversion.apply怎么用?Java CurrencyConversion.apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.money.convert.CurrencyConversion
的用法示例。
在下文中一共展示了CurrencyConversion.apply方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldHaveExchangeRates
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@Test
public void shouldHaveExchangeRates() {
CurrencyConversion currencyConversion = provider.getCurrencyConversion(DOLLAR);
assertNotNull(currencyConversion);
int count = 0;
for (Currency currency : Currency.getAvailableCurrencies()) {
MonetaryAmount money = Money.of(BigDecimal.ONE, currency.getCurrencyCode());
try {
MonetaryAmount result = currencyConversion.apply(money);
assertTrue(result.getNumber().doubleValue() > 0);
count++;
} catch(Exception e) {
//not a supported currency
}
}
assertTrue(count >=24);
}
示例2: shouldSetTimeInLocalDateTime
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@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);
}
示例3: shouldReturnErrorWhenFindFromHistoricalUsingPeriod
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@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();
}
示例4: main
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
public static void main(String[] args) {
CurrencyUnit dollar = Monetary.getCurrency("USD");
CurrencyUnit real = Monetary.getCurrency("BRL");
MonetaryAmount money = FastMoney.of(10, dollar);
MonetaryAmount money2 = FastMoney.of(10, real);
ExchangeRateProvider provider = MonetaryConversions.getExchangeRateProvider(ExchangeRateType.ECB);
CurrencyConversion currencyConversion = provider.getCurrencyConversion(dollar);
MonetaryAmount result = currencyConversion.apply(money2);
MonetaryAmount monetaryAmount = money.add(result);
}
示例5: shouldConvertsEuroToDollar
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@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);
}
示例6: shouldReturnsSameDollarValue
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@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);
}
示例7: shouldReturnsSameBrazilianValue
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@Test
public void shouldReturnsSameBrazilianValue() {
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(BRAZILIAN_REAL);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), BRAZILIAN_REAL);
assertEquals(result.getNumber().numberValue(BigDecimal.class),
BigDecimal.TEN);
}
示例8: shouldReturnsSameEuroValue
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@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);
}
示例9: shouldConvertsDolarToEuro
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@Test
public void shouldConvertsDolarToEuro() {
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);
}
示例10: shouldConvertsDollarToEuro
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@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);
}
示例11: shouldConvertsDollarToBrazilian
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@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);
}
示例12: shouldConvertsBrazilianToDollar
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@Test
public void shouldConvertsBrazilianToDollar() {
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(DOLLAR);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, BRAZILIAN_REAL);
MonetaryAmount result = currencyConversion.apply(money);
assertEquals(result.getCurrency(), DOLLAR);
assertTrue(result.getNumber().doubleValue() > 0);
}
示例13: shouldReturnErrorWhenDoesNotFindTheExchangeRate
import javax.money.convert.CurrencyConversion; //导入方法依赖的package包/类
@Test(expectedExceptions = MonetaryException.class)
public void shouldReturnErrorWhenDoesNotFindTheExchangeRate() {
LocalDate localDate = YearMonth.of(2011, Month.JANUARY).atDay(9);
ConversionQuery conversionQuery = HistoricConversionQueryBuilder
.of(EURO).withDay(localDate).build();
CurrencyConversion currencyConversion = provider
.getCurrencyConversion(conversionQuery);
assertNotNull(currencyConversion);
MonetaryAmount money = Money.of(BigDecimal.TEN, DOLLAR);
currencyConversion.apply(money);
fail();
}