added base class for testing iterators

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@130578 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Morgan James Delagrange 2002-02-25 23:26:43 +00:00
parent eb9884cd91
commit d3a61e7648
1 changed files with 53 additions and 4 deletions

View File

@ -4,13 +4,14 @@ package org.apache.commons.collections;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.framework.Test;
import java.util.Iterator;
import java.util.NoSuchElementException;
/**
*
* @author Jan Sorensen
*/
public class TestFilterIterator extends TestCase {
public class TestFilterIterator extends TestIterator {
/** Creates new TestFilterIterator */
public TestFilterIterator(String name) {
@ -41,6 +42,30 @@ public class TestFilterIterator extends TestCase {
return (new TestSuite(TestFilterIterator.class));
}
/**
* Returns an full iterator wrapped in a
* FilterIterator that blocks all the elements
*
* @return "empty" FilterIterator
*/
public Iterator makeEmptyIterator() {
return makeBlockAllFilter(new ArrayIterator(array));
}
/**
* Returns an array with elements wrapped in a pass-through
* FilterIterator
*
* @return
*/
public Iterator makeFullIterator() {
return makePassThroughFilter(new ArrayIterator(array));
}
public Object makeObject() {
return makeFullIterator();
}
public void testRepeatedHasNext() {
for (int i = 0; i <= array.length; i++) {
assertTrue(iterator.hasNext());
@ -95,11 +120,35 @@ public class TestFilterIterator extends TestCase {
}
private void initIterator() {
iterator = new FilterIterator(new ArrayIterator(array));
iterator = makePassThroughFilter(new ArrayIterator(array));
}
/**
* Returns a FilterIterator that does not filter
* any of its elements
*
* @param i the Iterator to "filter"
* @return "filtered" iterator
*/
protected FilterIterator makePassThroughFilter(Iterator i) {
Predicate pred = new Predicate() {
public boolean evaluate(Object x) { return true; }
public boolean evaluate(Object x) { return true; }
};
iterator.setPredicate(pred);
return new FilterIterator(i,pred);
}
/**
* Returns a FilterIterator that blocks
* all of its elements
*
* @param i the Iterator to "filter"
* @return "filtered" iterator
*/
protected FilterIterator makeBlockAllFilter(Iterator i) {
Predicate pred = new Predicate() {
public boolean evaluate(Object x) { return false; }
};
return new FilterIterator(i,pred);
}
}