KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import java.util.ArrayList JavaDoc;
23 import java.util.Iterator JavaDoc;
24 import java.util.List JavaDoc;
25 import java.util.NoSuchElementException JavaDoc;
26 import java.util.Random JavaDoc;
27 import junit.framework.*;
28 import org.netbeans.modules.java.source.TestUtil;
29
30 /** Basic class for testing iterators.
31  *
32  * @author Petr Hrebejk
33  */

34 public class IteratorToIterableTest extends TestCase {
35
36     public IteratorToIterableTest(String JavaDoc testName) {
37         super(testName);
38     }
39
40     protected void setUp() throws Exception JavaDoc {
41     }
42
43     protected void tearDown() throws Exception JavaDoc {
44     }
45
46     public static Test suite() {
47         TestSuite suite = new TestSuite(IteratorToIterableTest.class);
48         return suite;
49     }
50     
51     // Test Methods ------------------------------------------------------------
52

53     public void testValues() {
54         
55         List JavaDoc<Integer JavaDoc> gl = IteratorTest.createSequentialList( 100 );
56         
57         String JavaDoc diff = TestUtil.collectionDiff( gl, Iterators.toIterable( gl.iterator() ) );
58         assertEquals( "Diff should be empty", "", diff );
59         
60     }
61     
62     public void testEmptyValues() {
63         
64         List JavaDoc<Integer JavaDoc> gl = new ArrayList JavaDoc<Integer JavaDoc>();
65         
66         String JavaDoc diff = TestUtil.collectionDiff( gl, Iterators.toIterable( gl.iterator() ) );
67         assertEquals( "Diff should be empty", "", diff );
68         
69     }
70     
71     public void testInvalidParametrs() {
72         
73         try {
74             Iterators.toIterable( null );
75             fail( "IllegalArgumentException should have been thrown, but was not.");
76         }
77         catch( IllegalArgumentException JavaDoc e ) {
78             // Fine
79
}
80     
81     }
82         
83 }
84
Popular Tags