RateService { public Rate getLatest(String fromcur, String tocur) { LatestRate lr = latestRateRepository.findByFromcurCodeAndTocurCode(fromcur, tocur); if (lr != null) { return rateMapper.mapToRate(lr); } LatestRate lrBaseCurrency = latestRateRepository.findByFromcurCodeAndTocurCode(BASE_CURRENCY, tocur); LatestRate lrBaseCurrencyFromcur = latestRateRepository.findByFromcurCodeAndTocurCode(BASE_CURRENCY, fromcur); final BigDecimal rate; final SymbolEntity symbolFromcur; final SymbolEntity symbolTocur; Instant rateDate = lrBaseCurrencyFromcur.getDate(); if (BASE_CURRENCY.equals(tocur)) { rate = MathUtils.invert(lrBaseCurrencyFromcur.getValue()); symbolFromcur = lrBaseCurrencyFromcur.getTocur(); symbolTocur = lrBaseCurrencyFromcur.getFromcur(); } else { rate = MathUtils.divide(lrBaseCurrency.getValue(), lrBaseCurrencyFromcur.getValue()); if (rateDate.isBefore(lrBaseCurrency.getDate())) { rateDate = lrBaseCurrency.getDate(); } symbolFromcur = lrBaseCurrencyFromcur.getTocur(); symbolTocur = lrBaseCurrency.getTocur(); } return rateMapper.mapToRate(new LatestRate(symbolFromcur, symbolTocur, rate, rateDate)); }  List<FavoriteRate> getAllLatestWithFavorites(String username); Instant getOldestRateDate(String fromcur, String tocur); Instant getNewestRateDate(String fromcur, String tocur); Rate getLatest(String fromcur, String tocur); void addLatestRate(Quote quote); List<DateValue> getHistoricalValues(String fromcur, String tocur, Instant startDate, Instant endDate); @Transactional void addHistoricalRates(List<Quote> quotes);  }
@Test public void testGetLatest_Computed() { Rate result = rateService.getLatest(EUR, GBP); assertThat(result.getFromcur().getCode()).isEqualTo(EUR); assertThat(result.getTocur().getCode()).isEqualTo(GBP); assertThat(result.getValue()).isEqualByComparingTo("0.7556613636"); assertThat(result.getDate()).isEqualTo(parse("2015-02-02T08:42:50")); }
@Test public void testGetLatest_Direct() { Rate result = rateService.getLatest(USD, GBP); assertThat(result.getFromcur().getCode()).isEqualTo(USD); assertThat(result.getTocur().getCode()).isEqualTo(GBP); assertThat(result.getValue()).isEqualByComparingTo("0.664982"); assertThat(result.getDate()).isEqualTo(parse("2015-02-02T08:42:50")); }