|
What this is
Other links
The source code
/*
* Copyright 2001-2004 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.collections.iterators;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.commons.collections.comparators.ComparableComparator;
/**
* Unit test suite for {@link CollatingIterator}.
*
* @version $Revision: 1.6 $ $Date: 2004/02/18 01:20:33 $
* @author Rodney Waldhoff
*/
public class TestCollatingIterator extends AbstractTestIterator {
//------------------------------------------------------------ Conventional
public TestCollatingIterator(String testName) {
super(testName);
}
public static Test suite() {
return new TestSuite(TestCollatingIterator.class);
}
//--------------------------------------------------------------- Lifecycle
private Comparator comparator = null;
private ArrayList evens = null;
private ArrayList odds = null;
private ArrayList fib = null;
public void setUp() throws Exception {
super.setUp();
comparator = new ComparableComparator();
evens = new ArrayList();
odds = new ArrayList();
for(int i=0;i<20;i++) {
if(0 == i%2) {
evens.add(new Integer(i));
} else {
odds.add(new Integer(i));
}
}
fib = new ArrayList();
fib.add(new Integer(1));
fib.add(new Integer(1));
fib.add(new Integer(2));
fib.add(new Integer(3));
fib.add(new Integer(5));
fib.add(new Integer(8));
fib.add(new Integer(13));
fib.add(new Integer(21));
}
//---------------------------------------------------- TestIterator Methods
public Iterator makeEmptyIterator() {
return new CollatingIterator(comparator);
}
public Iterator makeFullIterator() {
CollatingIterator iter = new CollatingIterator(comparator);
iter.addIterator(evens.iterator());
iter.addIterator(odds.iterator());
iter.addIterator(fib.iterator());
return iter;
}
//------------------------------------------------------------------- Tests
public void testGetSetComparator() {
CollatingIterator iter = new CollatingIterator();
assertNull(iter.getComparator());
iter.setComparator(comparator);
assertSame(comparator,iter.getComparator());
iter.setComparator(null);
assertNull(iter.getComparator());
}
public void testIterateEven() {
CollatingIterator iter = new CollatingIterator(comparator);
iter.addIterator(evens.iterator());
for(int i=0;i |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.