YahooStockProvider implements LatestRateProvider, HistoricalRateProvider { @Override public List<Quote> getRates() throws IOException { List<Quote> rates = new ArrayList<>(); List<Pair> symbols = pairService.getAllFromProvider("YAHOO"); if (symbols.isEmpty()) { log.trace("symbols list is empty"); return rates; } YahooModel result = rt.getForObject(format(url, createPairsString(symbols)), YahooModel.class); return result.getQuoteResponse().getResult().stream() .map(yf -> new Quote(getSource(symbols, yf.getSymbol()), getCurrency(symbols, yf.getSymbol()), BigDecimal.valueOf(yf.getRegularMarketPrice()), toInstant(yf.getRegularMarketTime()))) .collect(Collectors.toList()); }  @Override List<Quote> getRates(); @Override Quote getLatestRate(String symbol); @Override List<Quote> getHistoricalRates(); @Override List<Quote> getHistoricalRates(String code);  }
@Test public void testGetRates() throws Exception { server.expect(anything()).andRespond(withSuccess(LATEST, MediaType.APPLICATION_JSON)); Quote expectedUbisoftRate = new Quote("UBI", EUR, new BigDecimal("57.52"), parse("2017-09-08T17:35:14+02:00")); Quote expectedLitecoinRate = new Quote("LTC", USD, new BigDecimal("67.29928"), parse("2017-09-10T15:19:23+02:00")); var symbols = List.of( new Pair().setSymbol("UBI.PA").setName("Ubi").setSource(new Symbol().setCode("UBI")).setTarget(new Symbol().setCode(EUR)).setProviderCode("YAHOO"), new Pair().setSymbol("LTCUSD=X").setName("Litecoin").setSource(new Symbol().setCode("LTC")).setTarget(new Symbol().setCode(USD)).setProviderCode("YAHOO") ); when(pairService.getAllFromProvider(ArgumentMatchers.anyString())).thenReturn(symbols); List<Quote> result = yahooStock.getRates(); assertThat(result).containsOnlyOnce(expectedLitecoinRate, expectedUbisoftRate); }