1 );
List list;
final FactHandle h1 = workingMemory.insert( cheese1 );
workingMemory.fireAllRules();
list = IteratorToList.convert( workingMemory.iterateObjects( new ClassObjectFilter( cheese1.getType().getClass() ) ) );
assertEquals( 1,
list.size() );
// probably dangerous, as contains works with equals, not identity
assertEquals( cheese1.getType(),
list.get( 0 ) );
// FactHandle ht = workingMemory.getFactHandle(c1.getType());
final FactHandle h2 = workingMemory.insert( cheese2 );
workingMemory.fireAllRules();
list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
assertEquals( 1,
list.size() );
assertEquals( cheese1.getType(),
list.get( 0 ) );
assertEquals( 3, IteratorToList.convert( workingMemory.iterateObjects() ).size() );
workingMemory.retract( h1 );
workingMemory.fireAllRules();
list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
assertEquals( "cheese-type " + cheese1.getType() + " was retracted, but should not. Backed by cheese2 => type.",
1,
list.size() );
assertEquals( "cheese-type " + cheese1.getType() + " was retracted, but should not. Backed by cheese2 => type.",
cheese1.getType(),
list.get( 0 ) );
workingMemory.retract( h2 );
workingMemory.fireAllRules();
list = IteratorToList.convert( workingMemory.iterateObjects(new ClassObjectFilter( cheese1.getType().getClass() ) ) );
assertEquals( "cheese-type " + cheese1.getType() + " was not retracted, but should have. Neither cheese1 => type nor cheese2 => type is true.",
0,
list.size() );
}