BarBuilder implements IBarBuilder { public void stop() { try { scheduler.deleteJob( job.getKey() ); } catch (SchedulerException ex) { throw new IllegalStateException( 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 testStop() 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 JobDetail job = RealtimeBarUtil.buildJob(jobName, null); 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))); 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(mockScheduler).deleteJob(job.getKey()); } }); BarBuilder builder = new BarBuilder(mockFactory, request, mockHistoricalDataProvider); builder.stop(); mockery.assertIsSatisfied(); }
@Test public void testStop_ThrowsException() 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 JobDetail job = RealtimeBarUtil.buildJob(jobName, null); 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))); 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(mockScheduler).deleteJob(job.getKey()); will(throwException(new SchedulerException())); } }); BarBuilder builder = new BarBuilder(mockFactory, request, mockHistoricalDataProvider); try { builder.stop(); fail(); } catch (IllegalStateException ex) { } mockery.assertIsSatisfied(); }