### Question:
Market { public void add(long instrument, long orderId, Side side, long price, long size) { if (orders.containsKey(orderId)) return; OrderBook book = books.get(instrument); if (book == null) return; Order order = new Order(book, side, price, size); boolean bbo = book.add(side, price, size); orders.put(orderId, order); listener.update(book, bbo); } Market(MarketListener listener); OrderBook open(long instrument); Order find(long orderId); void add(long instrument, long orderId, Side side, long price, long size); void modify(long orderId, long size); long execute(long orderId, long quantity); long execute(long orderId, long quantity, long price); long cancel(long orderId, long quantity); void delete(long orderId);  }### Answer:
@Test public void bbo() { market.add(INSTRUMENT, 1, Side.BUY, 999, 100); market.add(INSTRUMENT, 2, Side.SELL, 1001, 200); assertEquals(asList(new Level(999, 100, 1001, 200)), levels(book)); Event updateAfterBid = new Update(INSTRUMENT, true); Event updateAfterAsk = new Update(INSTRUMENT, true); assertEquals(asList(updateAfterBid, updateAfterAsk), events.collect()); }
@Test public void addition() { market.add(INSTRUMENT, 1, Side.BUY, 999, 100); market.add(INSTRUMENT, 2, Side.SELL, 1001, 200); market.add(INSTRUMENT, 3, Side.BUY, 1000, 50); assertEquals(asList(new Level(1000, 50, 1001, 200), new Level(999, 100, 0, 0)), levels(book)); Event updateAfterFirstBid = new Update(INSTRUMENT, true); Event updateAfterAsk = new Update(INSTRUMENT, true); Event updateAfterSecondBid = new Update(INSTRUMENT, true); assertEquals(asList(updateAfterFirstBid, updateAfterAsk, updateAfterSecondBid), events.collect()); }