01: package org.drools.common;
02:
03: import org.drools.Cheese;
04: import org.drools.reteoo.ReteooFactHandleFactory;
05: import org.drools.spi.FactHandleFactory;
06:
07: import junit.framework.TestCase;
08:
09: public class EqualityKeyTest extends TestCase {
10: public void test1() {
11: ReteooFactHandleFactory factory = new ReteooFactHandleFactory();
12:
13: InternalFactHandle ch1 = factory.newFactHandle(new Cheese("c",
14: 10));
15: EqualityKey key = new EqualityKey(ch1);
16:
17: assertSame(ch1, key.getFactHandle());
18: assertNull(key.getOtherFactHandle());
19:
20: InternalFactHandle ch2 = factory.newFactHandle(new Cheese("c",
21: 10));
22: key.addFactHandle(ch2);
23:
24: assertEquals(1, key.getOtherFactHandle().size());
25: assertEquals(ch2, key.getOtherFactHandle().get(0));
26:
27: key.removeFactHandle(ch1);
28: assertSame(ch2, key.getFactHandle());
29: assertNull(key.getOtherFactHandle());
30:
31: key.removeFactHandle(ch2);
32: assertNull(key.getFactHandle());
33: assertNull(key.getOtherFactHandle());
34:
35: key = new EqualityKey(ch2);
36: key.addFactHandle(ch1);
37: assertSame(ch2, key.getFactHandle());
38: assertEquals(1, key.getOtherFactHandle().size());
39: assertEquals(ch1, key.getOtherFactHandle().get(0));
40:
41: key.removeFactHandle(ch1);
42: assertSame(ch2, key.getFactHandle());
43: assertNull(key.getOtherFactHandle());
44:
45: key.removeFactHandle(ch2);
46: assertNull(key.getFactHandle());
47: assertNull(key.getOtherFactHandle());
48: }
49: }
|