Collective2Broker implements IBroker { @Override public void placeOrder(TradeOrder order) { logger.info("Submitting order to C2 Broker: " + order); SubmitSignalResponse submitTradeSignalResponse = c2Client.submitTradeSignal(signalBuilder.buildSignalRequest(systemid, order)); logger.info("C2 parent response: " + submitTradeSignalResponse.toString() ); order.setOrderId(submitTradeSignalResponse.getSignalid()); for( TradeOrder child : order.getChildOrders() ) { logger.info("Submitting child order"); SubmitSignalRequest buildSignalRequest = signalBuilder.buildSignalRequest(systemid, child); logger.info("C2 Child Signal: " + buildSignalRequest ); submitTradeSignalResponse = c2Client.submitTradeSignal(buildSignalRequest); logger.info("C2 child response: " + submitTradeSignalResponse.toString() ); child.setOrderId(submitTradeSignalResponse.getSignalid()); } } protected  Collective2Broker();  Collective2Broker(String apiKey, String systemid ); @Override void cancelOrder(String id); @Override void cancelOrder(TradeOrder order); @Override void placeOrder(TradeOrder order); @Override String getNextOrderId(); @Override void addOrderEventListener(OrderEventListener listener); @Override void removeOrderEventListener(OrderEventListener listener); @Override void addBrokerErrorListener(BrokerErrorListener listener); @Override void removeBrokerErrorListener(BrokerErrorListener listener); @Override String getFormattedDate(int hour, int minute, int second); @Override String getFormattedDate(ZonedDateTime date); @Override ZonedDateTime getCurrentTime(); @Override void connect(); @Override void disconnect(); @Override boolean isConnected(); @Override void aquireLock(); @Override void releaseLock(); @Override ComboTicker buildComboTicker(Ticker ticker1, Ticker ticker2); @Override ComboTicker buildComboTicker(Ticker ticker1, int ratio1, Ticker ticker2, int ratio2); @Override TradeOrder requestOrderStatus(String orderId); @Override List<TradeOrder> getOpenOrders(); @Override void cancelAndReplaceOrder(String originalOrderId, TradeOrder newOrder); @Override void addTimeUpdateListener(TimeUpdatedListener listener); @Override void removeTimeUpdateListener(TimeUpdatedListener listener); @Override List<Position> getAllPositions();  }
@Test public void testPlaceOrder() { TradeOrder parentOrder = new TradeOrder(); TradeOrder childOrder = new TradeOrder(); parentOrder.addChildOrder(childOrder); SubmitSignalRequest request1 = mock(SubmitSignalRequest.class); SubmitSignalRequest request2 = mock(SubmitSignalRequest.class); SubmitSignalResponse parentReponse = new SubmitSignalResponse(); parentReponse.setSignalid("parent-123"); SubmitSignalResponse childResponse = new SubmitSignalResponse(); childResponse.setSignalid("child-123"); when(mockSignalBuilder.buildSignalRequest(systemId, parentOrder)).thenReturn(request1); when(mockSignalBuilder.buildSignalRequest(systemId, childOrder)).thenReturn(request2); when(mockC2Client.submitTradeSignal(request1)).thenReturn(parentReponse); when(mockC2Client.submitTradeSignal(request2)).thenReturn(childResponse); testBroker.placeOrder(parentOrder); assertEquals("parent-123", parentOrder.getOrderId()); assertEquals("child-123", childOrder.getOrderId()); }