BarBuilder implements IBarBuilder { protected void fireEvent(BarData bar) { synchronized (listenerList) { for (RealtimeBarListener listener : listenerList) { try { listener.realtimeBarReceived(realtimeBarRequest.getRequestId(), realtimeBarRequest.getTicker(), bar); } catch( Exception ex ) { logger.error(ex.getMessage(), ex); } } } } 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 testFireEvent() 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 RealtimeBarListener mockListener = mockery.mock(RealtimeBarListener.class); 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); final BarData expectedBar = new BarData(); expectedBar.setOpen(open); expectedBar.setHigh(high); expectedBar.setLow(low); expectedBar.setClose(close); expectedBar.setVolume(volume); expectedBar.setDateTime(LocalDateTime.now()); 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)); one(mockListener).realtimeBarReceived(request.getRequestId(), request.getTicker(), expectedBar); } }); BarBuilder builder = new BarBuilder(mockFactory, request, mockHistoricalDataProvider); builder.addBarListener(mockListener); builder.fireEvent(expectedBar); mockery.assertIsSatisfied(); }