ItBitExchangeAdapter extends AbstractExchangeAdapter implements ExchangeAdapter { @Override public BigDecimal getLatestMarketPrice(String marketId) throws TradingApiException, ExchangeNetworkException { ExchangeHttpResponse response = null; try { response = sendPublicRequestToExchange(MARKETS_RESOURCE + "/" + marketId + "/ticker"); if (LOG.isDebugEnabled()) { LOG.debug("Latest Market Price response: {}", response); } if (response.getStatusCode() == HttpURLConnection.HTTP_OK) { final ItBitTicker itBitTicker = gson.fromJson(response.getPayload(), ItBitTicker.class); return itBitTicker.lastPrice; } else { final String errorMsg = "Failed to get market ticker from exchange. Details: " + response; LOG.error(errorMsg); throw new TradingApiException(errorMsg); } } catch (ExchangeNetworkException | TradingApiException e) { throw e; } catch (Exception e) { if (isExchangeUndergoingMaintenance(response) && keepAliveDuringMaintenance) { LOG.warn(() -> UNDER_MAINTENANCE_WARNING_MESSAGE); throw new ExchangeNetworkException(UNDER_MAINTENANCE_WARNING_MESSAGE); } final String unexpectedErrorMsg = UNEXPECTED_ERROR_MSG + (response == null ? NULL_RESPONSE : response); LOG.error(unexpectedErrorMsg, e); throw new TradingApiException(unexpectedErrorMsg, e); } }  @Override void init(ExchangeConfig config); @Override String createOrder(
      String marketId, OrderType orderType, BigDecimal quantity, BigDecimal price); @Override boolean cancelOrder(String orderId, String marketIdNotNeeded); @Override List<OpenOrder> getYourOpenOrders(String marketId); @Override MarketOrderBook getMarketOrders(String marketId); @Override BigDecimal getLatestMarketPrice(String marketId); @Override BalanceInfo getBalanceInfo(); @Override BigDecimal getPercentageOfBuyOrderTakenForExchangeFee(String marketId); @Override BigDecimal getPercentageOfSellOrderTakenForExchangeFee(String marketId); @Override String getImplName(); @Override Ticker getTicker(String marketId);  }
@Test(expected = ExchangeNetworkException.class) public void testGettingLatestMarketPriceHandlesExchangeNetworkException() throws Exception { final ItBitExchangeAdapter exchangeAdapter = PowerMock.createPartialMock( ItBitExchangeAdapter.class, MOCKED_SEND_PUBLIC_REQUEST_TO_EXCHANGE_METHOD); PowerMock.expectPrivate(exchangeAdapter, MOCKED_SEND_PUBLIC_REQUEST_TO_EXCHANGE_METHOD, TICKER) .andThrow( new ExchangeNetworkException( " I've seen horrors... horrors that you've seen." + " But you have no right to call me a murderer. You have a right to kill me. " + "You have a right to do that... but you have no right to judge me. It's " + "impossible for words to describe what is necessary to those who do not " + "know what horror means. Horror... Horror has a face... and you must make a " + "friend of horror. Horror and moral terror are your friends. " + "If they are not, then they are enemies to be feared.")); PowerMock.replayAll(); exchangeAdapter.getLatestMarketPrice(MARKET_ID); PowerMock.verifyAll(); }
@Test(expected = TradingApiException.class) public void testGettingLatestMarketPriceHandlesUnexpectedException() throws Exception { final ItBitExchangeAdapter exchangeAdapter = PowerMock.createPartialMock( ItBitExchangeAdapter.class, MOCKED_SEND_PUBLIC_REQUEST_TO_EXCHANGE_METHOD); PowerMock.expectPrivate(exchangeAdapter, MOCKED_SEND_PUBLIC_REQUEST_TO_EXCHANGE_METHOD, TICKER) .andThrow(new IllegalArgumentException("The horror... the horror...")); PowerMock.replayAll(); exchangeAdapter.getLatestMarketPrice(MARKET_ID); PowerMock.verifyAll(); }