KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > iterators > TestUniqueFilterIterator


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.iterators;
17
18 import java.util.ArrayList JavaDoc;
19 import java.util.Iterator JavaDoc;
20 import java.util.List JavaDoc;
21 import java.util.NoSuchElementException JavaDoc;
22
23 import junit.framework.Test;
24 import junit.framework.TestSuite;
25
26 /**
27  * Tests the UniqueFilterIterator class.
28  *
29  * @version $Revision: 1.7 $ $Date: 2004/02/18 01:20:33 $
30  *
31  * @author James Strachan
32  * @author Mauricio S. Moura
33  * @author Morgan Delagrange
34  * @author Stephen Colebourne
35  */

36 public class TestUniqueFilterIterator extends AbstractTestIterator {
37
38     protected String JavaDoc[] testArray = {
39         "One", "Two", "Three", "Four", "Five", "Six"
40     };
41
42     protected List JavaDoc list1 = null;
43
44     public static Test suite() {
45         return new TestSuite(TestUniqueFilterIterator.class);
46     }
47
48     public TestUniqueFilterIterator(String JavaDoc testName) {
49         super(testName);
50     }
51
52     public void setUp() {
53         list1 = new ArrayList JavaDoc();
54         list1.add("One");
55         list1.add("Two");
56         list1.add("Three");
57         list1.add("Two");
58         list1.add("One");
59         list1.add("Four");
60         list1.add("Five");
61         list1.add("Five");
62         list1.add("Six");
63         list1.add("Five");
64     }
65
66     public Iterator JavaDoc makeEmptyIterator() {
67         ArrayList JavaDoc list = new ArrayList JavaDoc();
68         return new UniqueFilterIterator(list.iterator());
69     }
70
71     public Iterator JavaDoc makeFullIterator() {
72         Iterator JavaDoc i = list1.iterator();
73
74         return new UniqueFilterIterator(i);
75     }
76
77     public void testIterator() {
78         Iterator JavaDoc iter = (Iterator JavaDoc) makeFullIterator();
79         for ( int i = 0; i < testArray.length; i++ ) {
80             Object JavaDoc testValue = testArray[i];
81             Object JavaDoc iterValue = iter.next();
82
83             assertEquals( "Iteration value is correct", testValue, iterValue );
84         }
85
86         assertTrue("Iterator should now be empty", ! iter.hasNext() );
87
88         try {
89             Object JavaDoc testValue = iter.next();
90         } catch (Exception JavaDoc e) {
91             assertTrue("NoSuchElementException must be thrown",
92                        e.getClass().equals((new NoSuchElementException JavaDoc()).getClass()));
93         }
94     }
95
96 }
97
98
Popular Tags