コード例 #1
0
  @Test
  public void testShouldNotifyListenersWhenTradeDone() {

    TradeListener listener = mock(TradeListener.class);
    when(listener.getClientName()).thenReturn("test");

    OrderBook orderBook = mock(OrderBook.class);
    Trade trade = mock(Trade.class);

    Order order = mock(Order.class);
    when(order.getOrderID()).thenReturn(UUID.randomUUID());
    when(order.getClientName()).thenReturn("test");
    when(trade.getBid()).thenReturn(order);
    when(trade.getOffer()).thenReturn(order);

    List<Trade> result = new ArrayList<>();
    result.add(trade);
    when(orderBook.fillOrders()).thenReturn(result);

    OrderBookService service = new OrderBookService(orderBook);
    service.addListener(listener);

    service.placeOrder(order);

    verify(listener, atLeastOnce()).onTrade(trade);
  }
コード例 #2
0
  @Test
  public void testShouldCancelWhenReceiveCancelOrder() throws CancelOrderException {
    Order order = orderGetTest(OrderType.BUY, 1, (float) 1.0, new Date());
    orderBook.placeOrder(order);
    responses = orderBook.fillOrders();

    orderBook.cancelOrder(order.getOrderID());

    // check
    try {
      orderBook.cancelOrder(order.getOrderID());
      fail();
    } catch (CancelOrderException e) {
      // ok
    }
  }