ksession.fireAllRules();
ArgumentCaptor<AfterMatchFiredEvent> cap = ArgumentCaptor.forClass( AfterMatchFiredEvent.class );
Mockito.verify( ael ).afterMatchFired(cap.capture());
Match activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
is( 18 ) );
assertThat( ((Number) activation.getDeclarationValue( "$min" )).intValue(),
is( 3 ) );
assertThat( ((Number) activation.getDeclarationValue( "$avg" )).intValue(),
is( 6 ) );
Mockito.reset( ael );
// ---------------- 2nd scenario
final int index = 1;
cheese[index].setPrice( 9 );
ksession.update( cheeseHandles[index],
cheese[index] );
ksession.fireAllRules();
Mockito.verify( ael ).afterMatchFired(cap.capture());
activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
is( 24 ) );
assertThat( ((Number) activation.getDeclarationValue( "$min" )).intValue(),
is( 5 ) );
assertThat( ((Number) activation.getDeclarationValue( "$avg" )).intValue(),
is( 8 ) );
Mockito.reset( ael );
// ---------------- 3rd scenario
bob.setLikes( "brie" );
ksession.update( bobHandle,
bob );
ksession.fireAllRules();
Mockito.verify( ael ).afterMatchFired(cap.capture());
activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
is( 32 ) );
assertThat( ((Number) activation.getDeclarationValue( "$min" )).intValue(),
is( 15 ) );
assertThat( ((Number) activation.getDeclarationValue( "$avg" )).intValue(),
is( 16 ) );
Mockito.reset( ael );
// ---------------- 4th scenario
ksession.retract( cheeseHandles[3] );
ksession.fireAllRules();
Mockito.verify( ael ).afterMatchFired(cap.capture());
activation = cap.getValue().getMatch();
assertThat( ((Number) activation.getDeclarationValue( "$sum" )).intValue(),
is( 17 ) );
assertThat( ((Number) activation.getDeclarationValue( "$min" )).intValue(),
is( 17 ) );
assertThat( ((Number) activation.getDeclarationValue( "$avg" )).intValue(),
is( 17 ) );
}