OrderExecutionService implements Runnable { @PostConstruct public void init() { orderExecThread = new Thread(this, this.getClass().getSimpleName()); orderExecThread.start(); } OrderExecutionService(BlockingQueue<TradingDecision<N>> orderQueue,
			AccountInfoService<K, N> accountInfoService, OrderManagementProvider<M, N, K> orderManagementProvider,
			BaseTradingConfig baseTradingConfig, PreOrderValidationService<M, N, K> preOrderValidationService,
			CurrentPriceInfoProvider<N> currentPriceInfoProvider); @PostConstruct void init(); @PreDestroy void shutDown(); @Override void run();  }
@Test @SuppressWarnings("unchecked") public void placeOrderTest() { BlockingQueue<TradingDecision<N>> orderQueue = new LinkedBlockingQueue<TradingDecision<N>>(); AccountInfoService<Long, N> accountInfoService = mock(AccountInfoService.class); OrderManagementProvider<Long, N, Long> orderManagementProvider = mock(OrderManagementProvider.class); BaseTradingConfig baseTradingConfig = mock(BaseTradingConfig.class); PreOrderValidationService<Long, N, Long> preOrderValidationService = mock(PreOrderValidationService.class); CurrentPriceInfoProvider<N> currentPriceInfoProvider = mock(CurrentPriceInfoProvider.class); OrderExecutionService<Long, N, Long> service = new OrderExecutionService<Long, N, Long>(orderQueue, accountInfoService, orderManagementProvider, baseTradingConfig, preOrderValidationService, currentPriceInfoProvider); service.init(); TradeableInstrument<N> gbpaud = new TradeableInstrument<N>("GBP_AUD"); TradingSignal signal = TradingSignal.SHORT; TradingDecision<N> tradingDecision1 = new TradingDecision<N>(gbpaud, signal, 1.855, 2.21); TradingDecision<N> tradingDecision2 = new TradingDecision<N>(gbpaud, signal, 1.855, 2.21, 2.12); when(preOrderValidationService.checkInstrumentNotAlreadyTraded(gbpaud)).thenReturn(true); when(preOrderValidationService.checkLimitsForCcy(gbpaud, signal)).thenReturn(true); Collection<TradeableInstrument<N>> instruments = Lists.newArrayList(); instruments.add(gbpaud); Map<TradeableInstrument<N>, Price<N>> priceMap = Maps.newHashMap(); double bidPrice = 2.0557; double askPrice = 2.0562; priceMap.put(gbpaud, new Price<N>(gbpaud, bidPrice, askPrice, DateTime.now())); when(currentPriceInfoProvider.getCurrentPricesForInstruments(eq(instruments))).thenReturn(priceMap); when(preOrderValidationService.isInSafeZone(TradingSignal.SHORT, bidPrice, gbpaud)).thenReturn(true); when(accountInfoService.findAccountsToTrade()).thenReturn(Lists.newArrayList(TradingTestConstants.accountId)); when(baseTradingConfig.getMaxAllowedQuantity()).thenReturn(100); orderQueue.offer(tradingDecision1); orderQueue.offer(tradingDecision2); orderQueue.offer(new TradingDecision<N>(gbpaud, TradingSignal.NONE)); while (orderQueue.size() > 0) { try { Thread.sleep(2L); } catch (InterruptedException e) { e.printStackTrace(); } } verify(orderManagementProvider, times(2)).placeOrder(any(Order.class), eq(TradingTestConstants.accountId)); }