OandaTradeManagementProvider implements TradeManagementProvider<Long, String, Long> { @Override public boolean closeTrade(Long tradeId, Long accountId) { CloseableHttpClient httpClient = getHttpClient(); try { HttpDelete httpDelete = new HttpDelete(getTradeForAccountUrl(tradeId, accountId)); httpDelete.setHeader(authHeader); LOG.info(TradingUtils.executingRequestMsg(httpDelete)); HttpResponse resp = httpClient.execute(httpDelete); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { LOG.info(String.format("Trade %d successfully closed for account %d", tradeId, accountId)); return true; } else { LOG.warn(String.format("Trade %d could not be closed. Recd error code %d", tradeId, resp .getStatusLine().getStatusCode())); } } catch (Exception e) { LOG.warn("error deleting trade id:" + tradeId, e); } finally { TradingUtils.closeSilently(httpClient); } return false; } OandaTradeManagementProvider(String url, String accessToken); @Override Collection<Trade<Long, String, Long>> getTradesForAccount(Long accountId); @Override Trade<Long, String, Long> getTradeForAccount(Long tradeId, Long accountId); @Override boolean modifyTrade(Long accountId, Long tradeId, double stopLoss, double takeProfit); @Override boolean closeTrade(Long tradeId, Long accountId);  }
@Test public void closeTradeTest() throws Exception { OandaTradeManagementProvider service = new OandaTradeManagementProvider(OandaTestConstants.url, OandaTestConstants.accessToken); assertEquals("https: .getTradeForAccountUrl(OandaTestConstants.tradeId, OandaTestConstants.accountId)); OandaTradeManagementProvider spy = doMockStuff("src/test/resources/tradesForAccount123456.txt", service); boolean success = spy.closeTrade(OandaTestConstants.tradeId, OandaTestConstants.accountId); assertTrue(success); verify(spy.getHttpClient(), times(1)).execute(any(HttpDelete.class)); }