OandaOrderManagementProvider implements OrderManagementProvider<Long, String, Long> { @Override public Collection<Order<String, Long>> allPendingOrders() { return pendingOrdersForInstrument(null); } 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 @SuppressWarnings("unchecked") public void allOrders() throws Exception { AccountDataProvider<Long> accountDataProvider = mock(AccountDataProvider.class); Account<Long> account = mock(Account.class); when(accountDataProvider.getLatestAccountInfo()).thenReturn(Lists.newArrayList(account)); when(account.getAccountId()).thenReturn(OandaTestConstants.accountId); OandaOrderManagementProvider service = new OandaOrderManagementProvider(OandaTestConstants.url, OandaTestConstants.accessToken, accountDataProvider); OandaOrderManagementProvider spy = doMockStuff("src/test/resources/allOrders.txt", service); Collection<Order<String, Long>> pendingOrders = spy.allPendingOrders(); assertEquals(2, pendingOrders.size()); Iterator<Order<String, Long>> iterator = pendingOrders.iterator(); Order<String, Long> order1 = iterator.next(); Order<String, Long> order2 = iterator.next(); assertEquals("USD_CAD", order1.getInstrument().getInstrument()); assertEquals(TradingSignal.LONG, order1.getSide()); assertEquals(OrderType.LIMIT, order1.getType()); assertEquals(1.3, order1.getPrice(), OandaTestConstants.precision); assertEquals(1.2, order1.getStopLoss(), OandaTestConstants.precision); assertEquals(1.31, order1.getTakeProfit(), OandaTestConstants.precision); assertEquals(100l, order1.getUnits()); assertEquals("EUR_USD", order2.getInstrument().getInstrument()); assertEquals(TradingSignal.LONG, order2.getSide()); assertEquals(OrderType.LIMIT, order2.getType()); assertEquals(1.115, order2.getPrice(), OandaTestConstants.precision); assertEquals(150l, order2.getUnits(), OandaTestConstants.precision); assertEquals(0.0, order2.getStopLoss(), OandaTestConstants.precision); assertEquals(0.0, order2.getTakeProfit(), OandaTestConstants.precision); }