WorkingMemoryEventListener wml = mock( WorkingMemoryEventListener.class );
ksession.addEventListener( wml );
AgendaEventListener ael = mock( AgendaEventListener.class );
ksession.addEventListener( ael );
PseudoClockScheduler clock = ksession.getSessionClock();
final StockTickInterface st1 = new StockTick( 1,
"RHT",
100,
1000 );
final StockTickInterface st2 = new StockTick( 2,
"RHT",
100,
1000 );
ksession.insert( st1 );
ksession.insert( st2 );
verify( wml,
times( 2 ) ).objectInserted( any( org.drools.event.rule.ObjectInsertedEvent.class ) );
verify( ael,
times( 2 ) ).activationCreated( any( ActivationCreatedEvent.class ) );
assertThat( ksession.getObjects().size(),
equalTo( 2 ) );
assertThat( ksession.getObjects(),
hasItems( (Object) st1,
st2 ) );
int fired = ksession.fireAllRules();
assertThat( fired,
equalTo( 2 ) );
clock.advanceTime( 3,
TimeUnit.SECONDS );
ksession.fireAllRules();
assertThat( ksession.getObjects().size(),
equalTo( 0 ) );