MarketDepthBook implements IMarketDepthBook { @Override public BigDecimal getTotalSize() { BigDecimal size = BigDecimal.ZERO; for (MarketDepthLevel level : levels) { size = size.add(level.getSize()).setScale(level.getSize().scale(), RoundingMode.HALF_UP); } return size; } protected  MarketDepthBook(); static IMarketDepthBook newInstance(); static void setTestInstance( IMarketDepthBook book ); @Override Side getSide(); @Override void setSide(Side side); @Override void clearLevels(); @Override MarketDepthLevel[] getLevels(); @Override int getLevelCount(); @Override MarketDepthLevel getLevelAt(int index); @Override void addLevel(MarketDepthLevel level); @Override void insertLevel(int index, MarketDepthLevel level ); @Override void updateLevel(int index, MarketDepthLevel level ); @Override void deleteLevel( int index ); @Override void setLevels(MarketDepthLevel[] levelArray); @Override BigDecimal getTotalSize(); @Override BigDecimal getCumulativeSize(int level); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); @Override void sort();  }
@Test public void testGetTotalSize() { MarketDepthBook book = new MarketDepthBook( ); book.addLevel( new MarketDepthLevel( MarketDepthBook.Side.ASK, new BigDecimal("3.00"), 400 ) ); book.addLevel( new MarketDepthLevel( MarketDepthBook.Side.ASK, new BigDecimal("3.01"), 1000 ) ); book.addLevel( new MarketDepthLevel( MarketDepthBook.Side.ASK, new BigDecimal("3.02"), 200 ) ); assertEquals( 1600, book.getTotalSize().intValue() ); assertEquals( 400, book.getCumulativeSize(0).intValue() ); assertEquals( 1400, book.getCumulativeSize(1).intValue() ); assertEquals( 1600, book.getCumulativeSize(2).intValue() ); assertEquals( 1600, book.getCumulativeSize(5).intValue() ); assertEquals( 3, book.getLevelCount() ); assertEquals( 3, book.getLevels().length ); book.clearLevels(); assertEquals( 0, book.getLevelCount() ); }