### Question:
EventFeeder { public void feed() { if ( source.hasNext() ) { Event< ? > event = source.getNext(); FeedContext context = new FeedContext( event ); FeedTrigger trigger = new FeedTrigger(); trigger.setNextFireTime( event.getDate() ); FeedJob job = new FeedJob( source, sink, trigger, clock ); clock.scheduleJob( job, context, trigger ); } } EventFeeder(final TimerService clock,
                       final EventSource source,
                       final EventReceiver sink); void feed();  }### Answer:
@Test public void testFeedPseudoClock() { final Event< ? >[] events = new Event[]{new EventImpl<String>( 1000, "one" ), new EventImpl<String>( 1100, "two" ), new EventImpl<String>( 1120, "three" ), new EventImpl<String>( 1300, "four" ), new EventImpl<String>( 1550, "five" ), new EventImpl<String>( 1700, "six" ),}; final Iterator<Event< ? >> it = Arrays.asList( events ).iterator(); final EventSource source = mock( EventSource.class ); final EventReceiver receiver = mock( EventReceiver.class ); when( source.hasNext() ).thenAnswer( new Answer<Boolean>() { public Boolean answer(InvocationOnMock invocation) throws Throwable { return it.hasNext(); } } ); when( source.getNext() ).thenAnswer( new Answer<Event<?>>() { public Event< ? > answer(InvocationOnMock invocation) throws Throwable { return it.next(); } }); PseudoClockScheduler clock = new PseudoClockScheduler(); EventFeeder feeder = new EventFeeder( clock, source, receiver ); feeder.feed(); for( Event<?> event : events ) { clock.advanceTime( event.getTimestamp() - clock.getCurrentTime(), TimeUnit.MILLISECONDS ); } verify( source, times(7) ).hasNext(); verify( source, times(6) ).getNext(); }