@Test(expectedExceptions = IllegalArgumentException.class) public void shouldFailToConvertWhenAmountIsNull() { ratesService.convert(Currency.EUR, Currency.RUB, null); }
@Override public BigDecimal convert(Currency from, Currency to, BigDecimal amount) { Assert.notNull(amount); Map<Currency, BigDecimal> rates = getCurrentRates(); BigDecimal ratio = rates.get(to).divide(rates.get(from), 4, RoundingMode.HALF_UP); return amount.multiply(ratio); }
ExchangeRatesServiceImpl implements ExchangeRatesService { @Override public BigDecimal convert(Currency from, Currency to, BigDecimal amount) { Assert.notNull(amount); Map<Currency, BigDecimal> rates = getCurrentRates(); BigDecimal ratio = rates.get(to).divide(rates.get(from), 4, RoundingMode.HALF_UP); return amount.multiply(ratio); } }
ExchangeRatesServiceImpl implements ExchangeRatesService { @Override public BigDecimal convert(Currency from, Currency to, BigDecimal amount) { Assert.notNull(amount); Map<Currency, BigDecimal> rates = getCurrentRates(); BigDecimal ratio = rates.get(to).divide(rates.get(from), 4, RoundingMode.HALF_UP); return amount.multiply(ratio); }  }
ExchangeRatesServiceImpl implements ExchangeRatesService { @Override public BigDecimal convert(Currency from, Currency to, BigDecimal amount) { Assert.notNull(amount); Map<Currency, BigDecimal> rates = getCurrentRates(); BigDecimal ratio = rates.get(to).divide(rates.get(from), 4, RoundingMode.HALF_UP); return amount.multiply(ratio); }  @Override Map<Currency, BigDecimal> getCurrentRates(); @Override BigDecimal convert(Currency from, Currency to, BigDecimal amount); }
ExchangeRatesServiceImpl implements ExchangeRatesService { @Override public BigDecimal convert(Currency from, Currency to, BigDecimal amount) { Assert.notNull(amount); Map<Currency, BigDecimal> rates = getCurrentRates(); BigDecimal ratio = rates.get(to).divide(rates.get(from), 4, RoundingMode.HALF_UP); return amount.multiply(ratio); }  @Override Map<Currency, BigDecimal> getCurrentRates(); @Override BigDecimal convert(Currency from, Currency to, BigDecimal amount);  }