use of javax.money.convert.ConversionContext in project jsr354-ri by JavaMoney.
the class ExchangeRateBuilderTest method shouldReturnNPEWhenConversionContextIsNull.
@Test(expectedExceptions = NullPointerException.class)
public void shouldReturnNPEWhenConversionContextIsNull() {
ConversionContext context = null;
new ExchangeRateBuilder(context).setBase(CURRENCY).setTerm(CURRENCY).setFactor(NUMBER_FACTOR).build();
}
use of javax.money.convert.ConversionContext in project jsr354-ri by JavaMoney.
the class IMFAbstractRateProvider method getExchangeRate.
@Override
public ExchangeRate getExchangeRate(ConversionQuery conversionQuery) {
try {
if (loadLock.await(30, TimeUnit.SECONDS)) {
if (currencyToSdr.isEmpty()) {
return null;
}
if (!isAvailable(conversionQuery)) {
return null;
}
CurrencyUnit base = conversionQuery.getBaseCurrency();
CurrencyUnit term = conversionQuery.getCurrency();
LocalDate[] times = getQueryDates(conversionQuery);
ExchangeRate rate1 = getExchangeRate(currencyToSdr.get(base), times);
ExchangeRate rate2 = getExchangeRate(sdrToCurrency.get(term), times);
if (base.equals(SDR)) {
return rate2;
} else if (term.equals(SDR)) {
return rate1;
}
if (Objects.isNull(rate1) || Objects.isNull(rate2)) {
return null;
}
ConversionContext context = getExchangeContext("imf.digit.fraction");
ExchangeRateBuilder builder = new ExchangeRateBuilder(context);
builder.setBase(base);
builder.setTerm(term);
builder.setFactor(multiply(rate1.getFactor(), rate2.getFactor()));
builder.setRateChain(rate1, rate2);
return builder.build();
} else {
// Lets wait for a successful load only once, then answer requests as data is present.
loadLock.countDown();
throw new MonetaryException("Failed to load currency conversion data: " + loadState);
}
} catch (InterruptedException e) {
throw new MonetaryException("Failed to load currency conversion data: Load task has been interrupted.", e);
}
}
use of javax.money.convert.ConversionContext in project jsr354-ri-bp by JavaMoney.
the class ExchangeRateBuilderTest method shouldReturnNPEWhenConversionContextIsNull.
@Test(expectedExceptions = NullPointerException.class)
public void shouldReturnNPEWhenConversionContextIsNull() {
ConversionContext context = null;
new ExchangeRateBuilder(context).setBase(CURRENCY).setTerm(CURRENCY).setFactor(NUMBER_FACTOR).build();
}
Aggregations