final Event<String> event5 = new EventImpl<String>( 1550, "five" );
final Event<String> event6 = new EventImpl<String>( 1700, "six" );
// define a jmock sequence and state machine
final Sequence seq = context.sequence( "call sequence" );
final States ts = context.states( "timestamp" ).startsAs( String.valueOf( event1.getTimestamp() ) );
// create mock objects for the source and the receiver
final EventSource source = context.mock( EventSource.class );
final EventReceiver receiver = context.mock( EventReceiver.class );
// create the scheduler used by drools and the feeder to be tested
PseudoClockScheduler clock = new PseudoClockScheduler();
EventFeeder feeder = new EventFeeder( clock, source, receiver );
// create the expectations
context.checking( new Expectations() {{
// there is an event1, so, read and feed
oneOf( source ).hasNext(); inSequence( seq ); will( returnValue( true ) );
oneOf( source ).getNext(); inSequence( seq ); will( returnValue( event1 ) );
oneOf( receiver ).receive( event1 ); inSequence( seq ); when( ts.is( String.valueOf( event1.getTimestamp() ) ) );
then( ts.is( String.valueOf( event2.getTimestamp() ) ) );
// there is an event 2, so read and feed
oneOf( source ).hasNext(); inSequence( seq ); will( returnValue( true ) );
oneOf( source ).getNext(); inSequence( seq ); will( returnValue( event2 ) );
oneOf( receiver ).receive( event2 ); inSequence( seq ); when( ts.is( String.valueOf( event2.getTimestamp() ) ) );
then( ts.is( String.valueOf( event3.getTimestamp() ) ) );
// there is an event 3, so read and feed
oneOf( source ).hasNext(); inSequence( seq ); will( returnValue( true ) );
oneOf( source ).getNext(); inSequence( seq ); will( returnValue( event3 ) );
oneOf( receiver ).receive( event3 ); inSequence( seq ); when( ts.is( String.valueOf( event3.getTimestamp() ) ) );
then( ts.is( String.valueOf( event4.getTimestamp() ) ) );
// there is an event 4, so read and feed
oneOf( source ).hasNext(); inSequence( seq ); will( returnValue( true ) );
oneOf( source ).getNext(); inSequence( seq ); will( returnValue( event4 ) );
oneOf( receiver ).receive( event4 ); inSequence( seq ); when( ts.is( String.valueOf( event4.getTimestamp() ) ) );
then( ts.is( String.valueOf( event5.getTimestamp() ) ) );
// there is an event 5, so read and feed
oneOf( source ).hasNext(); inSequence( seq ); will( returnValue( true ) );
oneOf( source ).getNext(); inSequence( seq ); will( returnValue( event5 ) );
oneOf( receiver ).receive( event5 ); inSequence( seq ); when( ts.is( String.valueOf( event5.getTimestamp() ) ) );
then( ts.is( String.valueOf( event6.getTimestamp() ) ) );
// there is an event 6, so read and feed
oneOf( source ).hasNext(); inSequence( seq ); will( returnValue( true ) );
oneOf( source ).getNext(); inSequence( seq ); will( returnValue( event6 ) );
oneOf( receiver ).receive( event6 ); inSequence( seq ); when( ts.is( String.valueOf( event6.getTimestamp() ) ) );
// there are no more events
oneOf( source ).hasNext(); inSequence( seq ); will( returnValue( false ) );
}});