KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > source > util > ChainedIteratorTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.source.util;
21 import java.util.ArrayList JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.LinkedList JavaDoc;
24 import java.util.List JavaDoc;
25 import junit.framework.*;
26
27 /** Basic class for testing iterators.
28  *
29  * @author Petr Hrebejk
30  */

31 public class ChainedIteratorTest extends IteratorTest {
32
33     public ChainedIteratorTest(String JavaDoc testName) {
34         super(testName);
35     }
36
37     protected void setUp() throws Exception JavaDoc {
38     }
39
40     protected void tearDown() throws Exception JavaDoc {
41     }
42
43     public static Test suite() {
44         TestSuite suite = new TestSuite(ChainedIteratorTest.class);
45         return suite;
46     }
47     
48     // Protected methods -------------------------------------------------------
49

50     protected Iterable JavaDoc<IteratorDescription> createDescriptions() {
51     
52         List JavaDoc<IteratorDescription> descs = new ArrayList JavaDoc<IteratorDescription>();
53         
54         List JavaDoc<Integer JavaDoc> gl1 = IteratorTest.createSequentialList( 100 );
55         List JavaDoc<Integer JavaDoc> gl2 = IteratorTest.createSequentialList( 30 );
56         List JavaDoc<Integer JavaDoc> gl3 = IteratorTest.createSequentialList( 17 );
57         List JavaDoc<Integer JavaDoc> gle = new ArrayList JavaDoc<Integer JavaDoc>();
58         
59         List JavaDoc<Integer JavaDoc> gl = new LinkedList JavaDoc<Integer JavaDoc>();
60         gl.addAll( gl1 );
61         gl.addAll( gl2 );
62         gl.addAll( gl3 );
63                 
64         descs.add( new IteratorDescription( "FromArray",
65                                             Iterators.chained( gl1.iterator(), gl2.iterator(), gl3.iterator() ),
66                                             gl.iterator(),
67                                             gl.size(),
68                                             true ) );
69         
70         descs.add( new IteratorDescription( "FromArraySomeEmpty",
71                                             Iterators.chained( gle.iterator(), gl1.iterator(), gle.iterator(), gl2.iterator(), gl3.iterator(), gle.iterator() ),
72                                             gl.iterator(),
73                                             gl.size(),
74                                             true ) );
75         
76         List JavaDoc<Iterator JavaDoc<Integer JavaDoc>> itList = new LinkedList JavaDoc<Iterator JavaDoc<Integer JavaDoc>>( );
77         itList.add( gl1.iterator() );
78         itList.add( gl2.iterator() );
79         itList.add( gl3.iterator() );
80         
81         descs.add( new IteratorDescription( "FromCollection",
82                                             Iterators.chained( gl1.iterator(), gl2.iterator(), gl3.iterator() ),
83                                             gl.iterator(),
84                                             gl.size(),
85                                             true ) );
86         
87         itList = new LinkedList JavaDoc<Iterator JavaDoc<Integer JavaDoc>>( );
88         itList.add( gle.iterator() );
89         itList.add( gl1.iterator() );
90         itList.add( gl2.iterator() );
91         itList.add( gle.iterator() );
92         itList.add( gl3.iterator() );
93         itList.add( gle.iterator() );
94                 
95         descs.add( new IteratorDescription( "FromCollectionSomeEmpty",
96                                             Iterators.chained( gl1.iterator(), gl2.iterator(), gl3.iterator() ),
97                                             gl.iterator(),
98                                             gl.size(),
99                                             true ) );
100         
101         return descs;
102     }
103
104     // Additional Test Methods -------------------------------------------------
105

106     public void testInvalidParameters() {
107         
108         List JavaDoc<Integer JavaDoc> gl1 = IteratorTest.createSequentialList( 100 );
109         List JavaDoc<Integer JavaDoc> gl2 = IteratorTest.createSequentialList( 30 );
110                 
111         try {
112             Iterators.chained( gl1.iterator(), null, gl2.iterator() );
113             fail( "IllegalArgumentException should have been thrown, but was not.");
114         }
115         catch( IllegalArgumentException JavaDoc e ) {
116             // Fine
117
}
118         
119         List JavaDoc<Iterator JavaDoc<Integer JavaDoc>> il = new LinkedList JavaDoc<Iterator JavaDoc<Integer JavaDoc>>();
120         il.add( gl1.iterator() );
121         il.add( null );
122         il.add( gl2.iterator() );
123         
124         try {
125             Iterators.chained( il );
126             fail( "IllegalArgumentException should have been thrown, but was not.");
127         }
128         catch( IllegalArgumentException JavaDoc e ) {
129             // Fine
130
}
131         
132         
133     }
134     
135     
136 }
137
Popular Tags