BarBuilder implements IBarBuilder { public void buildBarAndFireEvents() { BarData bar = new BarData(); bar.setOpen(open); bar.setHigh(high); bar.setLow(low); bar.setClose(close); bar.setVolume(volume); bar.setDateTime(RealtimeBarUtil.getBarDate()); open = close; high = close; low = close; volume = BigDecimal.ZERO; openInitialized = false; highInitialized = false; lowInitialized = false; fireEvent(bar); } protected  BarBuilder();  BarBuilder(SchedulerFactory schedulerFactory, RealtimeBarRequest request, IHistoricalDataProvider historicalDataProvider); void quoteRecieved(ILevel1Quote quote); @Override void addBarListener(RealtimeBarListener listener); @Override void removeBarListener(RealtimeBarListener listener); void buildBarAndFireEvents(); int getListenerCount(); void stop();  }
@Test public void testBuildBarAndFireEvents() throws Exception { final SchedulerFactory mockFactory = mockery.mock(SchedulerFactory.class); final Scheduler mockScheduler = mockery.mock(Scheduler.class); final IHistoricalDataProvider mockHistoricalDataProvider = mockery.mock(IHistoricalDataProvider.class); Ticker ticker = new StockTicker("qqq"); final RealtimeBarRequest request = new RealtimeBarRequest(1, ticker, 1, LengthUnit.MINUTE); String jobName = RealtimeBarUtil.getJobName(request); final Trigger trigger = RealtimeBarUtil.getTrigger(jobName, request.getTimeInterval(), request.getTimeUnit()); final List<BarData> barList = new ArrayList<BarData>(); barList.add(new BarData(LocalDateTime.now(), new BigDecimal(2), new BigDecimal(3), new BigDecimal(2), new BigDecimal(2), new BigDecimal(10))); BigDecimal open = new BigDecimal(1.0); BigDecimal high = new BigDecimal(2.0); BigDecimal low = new BigDecimal(1.0); BigDecimal close = new BigDecimal(2.0); BigDecimal volume = new BigDecimal(100); mockery.checking(new Expectations() { { one(mockFactory).getScheduler(); will(returnValue(mockScheduler)); one(mockHistoricalDataProvider).requestHistoricalData(request.getTicker(), 1, LengthUnit.DAY, request.getTimeInterval(), request.getTimeUnit(), IHistoricalDataProvider.ShowProperty.TRADES, false); will(returnValue(barList)); one(mockScheduler).scheduleJob(with(any(JobDetail.class)), with(any(Trigger.class))); one(mockScheduler).isStarted(); will(returnValue(true)); } }); MockFireEventBarBuilder builder = new MockFireEventBarBuilder(mockFactory, request, mockHistoricalDataProvider); builder.openInitialized = false; builder.highInitialized = false; builder.lowInitialized = false; builder.volume = BigDecimal.ZERO; builder.setOpen(open); builder.setHigh(high); builder.setLow(low); builder.setClose(close); builder.setVolume(volume); LocalDateTime barDate = RealtimeBarUtil.getBarDate(); builder.buildBarAndFireEvents(); assertEquals(builder.close, builder.open); assertEquals(builder.close, builder.high); assertEquals(builder.close, builder.low); assertEquals(new BigDecimal(0), builder.volume); assertFalse(builder.highInitialized); assertFalse(builder.lowInitialized); assertFalse(builder.openInitialized); BarData expectedBar = new BarData(); expectedBar.setOpen(open); expectedBar.setHigh(high); expectedBar.setLow(low); expectedBar.setClose(close); expectedBar.setVolume(volume); expectedBar.setDateTime(barDate); assertEquals(expectedBar, builder.getBar()); mockery.assertIsSatisfied(); }