OandaOrderManagementProvider implements OrderManagementProvider<Long, String, Long> { @Override public boolean closeOrder(Long orderId, Long accountId) { CloseableHttpClient httpClient = getHttpClient(); try { HttpDelete httpDelete = new HttpDelete(orderForAccountUrl(accountId, orderId)); httpDelete.setHeader(authHeader); LOG.info(TradingUtils.executingRequestMsg(httpDelete)); HttpResponse resp = httpClient.execute(httpDelete); if (resp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { LOG.info(String.format("Order %d successfully deleted for account %d", orderId, accountId)); return true; } else { LOG.warn(String.format("Order %d could not be deleted. Recd error code %d", orderId, resp .getStatusLine().getStatusCode())); } } catch (Exception e) { LOG.warn("error deleting order id:" + orderId, e); } finally { TradingUtils.closeSilently(httpClient); } return false; } OandaOrderManagementProvider(String url, String accessToken, AccountDataProvider<Long> accountDataProvider); @Override boolean closeOrder(Long orderId, Long accountId); @Override Long placeOrder(Order<String, Long> order, Long accountId); @Override Order<String, Long> pendingOrderForAccount(Long orderId, Long accountId); @Override Collection<Order<String, Long>> pendingOrdersForInstrument(TradeableInstrument<String> instrument); @Override Collection<Order<String, Long>> allPendingOrders(); @Override Collection<Order<String, Long>> pendingOrdersForAccount(Long accountId); @Override boolean modifyOrder(Order<String, Long> order, Long accountId);  }
@Test public void closeOrderTest() throws Exception { OandaOrderManagementProvider service = new OandaOrderManagementProvider(OandaTestConstants.url, OandaTestConstants.accessToken, null); OandaOrderManagementProvider spy = doMockStuff("src/test/resources/orderForAccount123456.txt", service); boolean success = spy.closeOrder(OandaTestConstants.orderId, OandaTestConstants.accountId); assertTrue(success); verify(spy.getHttpClient(), times(1)).execute(any(HttpDelete.class)); }