KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.netbeans.modules.java.source.util.IteratorTest.IteratorDescription;
27
28 /** Basic class for testing iterators.
29  *
30  * @author Petr Hrebejk
31  */

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

51     protected Iterable JavaDoc<IteratorDescription> createDescriptions() {
52     
53         List JavaDoc<IteratorDescription> descs = new ArrayList JavaDoc<IteratorDescription>();
54         
55         List JavaDoc<Integer JavaDoc> gl = IteratorTest.createSequentialList( 100 );
56         List JavaDoc<String JavaDoc> sl = new LinkedList JavaDoc();
57         for( Integer JavaDoc i : gl ) {
58             sl.add( i.toString() );
59         }
60                 
61         descs.add( new IteratorDescription( "WithSomeElements",
62                                             Iterators.translating( gl.iterator(), Integer2TextFactory.INSTANCE ),
63                                             sl.iterator(),
64                                             gl.size(),
65                                             true ) );
66         
67         return descs;
68     }
69
70     // Additional Test Methods -------------------------------------------------
71

72     public void testInvalidParameters() {
73         
74         try {
75             Iterators.translating( (Iterator JavaDoc)null, Integer2TextFactory.INSTANCE );
76             fail( "IllegalArgumentException should have been thrown, but was not.");
77         }
78         catch( IllegalArgumentException JavaDoc e ) {
79             // Fine
80
}
81                 
82     }
83     
84     
85     // Innerclasses ------------------------------------------------------------
86

87     public static class Integer2TextFactory implements Factory<String JavaDoc,Integer JavaDoc> {
88     
89         public static Factory<String JavaDoc,Integer JavaDoc> INSTANCE = new Integer2TextFactory();
90         
91         private Integer2TextFactory() {} // No need to create instances
92

93         public String JavaDoc create(Integer JavaDoc parameter) {
94             return parameter.toString();
95         }
96         
97     }
98     
99 }
100
101
102
Popular Tags