📄 basebetarightmemorytestclass.java
字号:
this.memory.size() );
}
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.remove(WorkingMemory, ObjectMatches)'
*/
public void testRemoveUnexistingObjectMatches() {
try {
this.memory.remove( this.workingMemory,
this.matches0 );
Assert.fail( "Trying to remove an element that does not exist in the memory should throw an exception" );
} catch ( final Exception e ) {
// everything is fine
}
try {
final MultiLinkedListNodeWrapper wrapper0 = new MultiLinkedListNodeWrapper( this.matches0 );
this.memory.remove( this.workingMemory,
wrapper0 );
Assert.fail( "Trying to remove an element that does not exist in the memory should throw an exception" );
} catch ( final Exception e ) {
// everything is fine
}
try {
this.memory.remove( this.workingMemory,
(ObjectMatches) null );
Assert.fail( "Trying to remove a null element from memory should throw an exception" );
} catch ( final Exception e ) {
// everything is fine
}
try {
this.memory.remove( this.workingMemory,
(MultiLinkedListNodeWrapper) null );
Assert.fail( "Trying to remove a null element from memory should throw an exception" );
} catch ( final Exception e ) {
// everything is fine
}
}
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.isEmpty()'
*/
public void testIsEmpty() {
Assert.assertTrue( "Memory should be empty",
this.memory.isEmpty() );
this.memory.add( this.workingMemory,
this.matches0 );
Assert.assertFalse( "Memory should not be empty",
this.memory.isEmpty() );
}
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.size()'
*/
public void testSize() {
Assert.assertEquals( "Memory should have size 0",
0,
this.memory.size() );
this.memory.add( this.workingMemory,
this.matches0 );
Assert.assertEquals( "Memory should have size 1",
1,
this.memory.size() );
this.memory.add( this.workingMemory,
this.matches1 );
Assert.assertEquals( "Memory should have size 2",
2,
this.memory.size() );
this.memory.remove( this.workingMemory,
this.matches0 );
Assert.assertEquals( "Memory should have size 1",
1,
this.memory.size() );
this.memory.remove( this.workingMemory,
this.matches1 );
Assert.assertEquals( "Memory should have size 0",
0,
this.memory.size() );
}
public void testParameterlessIterator() {
try {
this.memory.add( this.workingMemory,
this.matches0 );
this.memory.add( this.workingMemory,
this.matches1 );
this.memory.add( this.workingMemory,
this.matches2 );
Assert.assertEquals( "Memory should have size 3",
3,
this.memory.size() );
final Iterator i = this.memory.iterator();
Assert.assertTrue( "There should be a next match",
i.hasNext() );
ObjectMatches matches = (ObjectMatches) i.next();
Assert.assertSame( "Wrong returned match",
this.matches0,
matches );
Assert.assertTrue( "There should be a next match",
i.hasNext() );
matches = (ObjectMatches) i.next();
Assert.assertSame( "Wrong returned match",
this.matches1,
matches );
Assert.assertTrue( "There should be a next match",
i.hasNext() );
matches = (ObjectMatches) i.next();
Assert.assertSame( "Wrong returned match",
this.matches2,
matches );
Assert.assertFalse( "There should not be a next match",
i.hasNext() );
} catch ( final UnsupportedOperationException e ) {
Assert.fail( "Beta memory was not supposed to throw any exception: " + e.getMessage() );
} catch ( final ClassCastException e ) {
Assert.fail( "BetaRightMemory was not supposed to throw ClassCastException: " + e.getMessage() );
}
}
public void testSelectPossibleMatches2() {
final int counter = this.child.getCounter();
this.memory.selectPossibleMatches( this.workingMemory,
this.tuple0 );
Assert.assertEquals( "Should have called inner memory",
counter + 1,
this.child.getCounter() );
}
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.selectPossibleMatches(WorkingMemory, ReteTuple)'
*/
public abstract void testSelectPossibleMatches();
/*
* Test method for 'org.drools.reteoo.beta.DefaultRightMemory.iterator(WorkingMemory, ReteTuple)'
*/
public abstract void testIterator();
/**
* Add an object to the index, then change indexed attribute, then do
* a remove;
*/
public abstract void testModifyObjectAttribute();
public static class MockBetaRightMemory
implements
BetaRightMemory {
private int callCounter = 0;
public void add(final WorkingMemory workingMemory,
final ObjectMatches matches) {
this.callCounter++;
}
public void add(final WorkingMemory workingMemory,
final MultiLinkedListNodeWrapper matches) {
this.callCounter++;
}
public boolean isEmpty() {
this.callCounter++;
return false;
}
public boolean isPossibleMatch(final MultiLinkedListNodeWrapper matches) {
this.callCounter++;
return true;
}
public Iterator iterator(final WorkingMemory workingMemory,
final ReteTuple tuple) {
this.callCounter++;
return null;
}
public Iterator iterator() {
this.callCounter++;
return null;
}
public void remove(final WorkingMemory workingMemory,
final ObjectMatches matches) {
this.callCounter++;
}
public void remove(final WorkingMemory workingMemory,
final MultiLinkedListNodeWrapper matches) {
this.callCounter++;
}
public void selectPossibleMatches(final WorkingMemory workingMemory,
final ReteTuple tuple) {
this.callCounter++;
}
public int size() {
return 0;
}
public int getCounter() {
return this.callCounter;
}
public BetaRightMemory getInnerMemory() throws OperationNotSupportedException {
return null;
}
public void setInnerMemory(final BetaRightMemory innerMemory) throws OperationNotSupportedException {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -