QuoineMarketDataService extends QuoineMarketDataServiceRaw implements MarketDataService { @Override public List<Ticker> getTickers(Params params) throws IOException { if (!(params instanceof CurrencyPairsParam)) { throw new IllegalArgumentException("Params must be instance of CurrencyPairsParam"); } CurrencyPairsParam pairs = (CurrencyPairsParam) params; QuoineProduct[] products = getQuoineProducts(); return Arrays.stream(products) .filter( product -> pairs.getCurrencyPairs().stream() .anyMatch( pair -> product.getBaseCurrency().equals(pair.base.getCurrencyCode()) && product .getQuotedCurrency() .equals(pair.counter.getCurrencyCode()))) .map(product -> QuoineAdapters.adaptTicker(product, buildCurrencyPair(product))) .collect(Collectors.toList()); } QuoineMarketDataService(Exchange exchange); @Override Ticker getTicker(CurrencyPair currencyPair, Object... args); @Override List<Ticker> getTickers(Params params); @Override OrderBook getOrderBook(CurrencyPair currencyPair, Object... args); @Override Trades getTrades(CurrencyPair currencyPair, Object... args);  }
@Test(expected = IllegalArgumentException.class) public void testGetTickersNullParam() throws IOException { service.getTickers(null); }
@Test(expected = IllegalArgumentException.class) public void testGetTickersWrongParamType() throws IOException { Params params = new Params() {}; service.getTickers(params); }
@Test public void testGetTickers() throws IOException { CurrencyPairsParam params = () -> Arrays.asList(CurrencyPair.BTC_USD, CurrencyPair.ETH_USD); List<Ticker> tickers = service.getTickers(params); assertEquals(params.getCurrencyPairs().size(), tickers.size()); Ticker btcUsd = tickers.stream() .filter(ticker -> ticker.getCurrencyPair().equals(CurrencyPair.BTC_USD)) .findFirst() .orElseThrow(() -> new NullPointerException("Required Ticker not found!")); Ticker ethUsd = tickers.stream() .filter(ticker -> ticker.getCurrencyPair().equals(CurrencyPair.ETH_USD)) .findFirst() .orElseThrow(() -> new NullPointerException("Required Ticker not found!")); assertNotNull(btcUsd); assertNotNull(ethUsd); }