YahooCurrencyProvider implements LatestRateProvider { @Override public List<Quote> getRates() throws IOException { YahooModel result = rt.getForObject(url, YahooModel.class); return result.getQuoteResponse().getResult().stream() .map(yf -> { Matcher m = FOREX_PATTERN.matcher(yf.getSymbol()); m.matches(); String source = m.group(1); String target = m.group(2); if (target == null) { target = source; source = CurrencyUtils.USD; } Instant inst = Instant.ofEpochSecond(yf.getRegularMarketTime()); return new Quote(source, target, BigDecimal.valueOf(yf.getRegularMarketPrice()), inst); }) .collect(Collectors.toList()); }  @Override List<Quote> getRates();  }
@Test public void testGetRates() throws Exception { server.expect(anything()).andRespond(withSuccess(LATEST, MediaType.APPLICATION_JSON)); Quote expectedUsdEurRate = new Quote(USD, EUR, new BigDecimal("0.8322"), parse("2017-09-11T10:01:00+02:00")); List<Quote> result = yahooCurrencyProvider.getRates(); assertThat(result).containsOnlyOnce(expectedUsdEurRate); }