1 19 20 package org.netbeans.modules.java.source.util; 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 import junit.framework.*; 26 27 31 public class ChainedIteratorTest extends IteratorTest { 32 33 public ChainedIteratorTest(String testName) { 34 super(testName); 35 } 36 37 protected void setUp() throws Exception { 38 } 39 40 protected void tearDown() throws Exception { 41 } 42 43 public static Test suite() { 44 TestSuite suite = new TestSuite(ChainedIteratorTest.class); 45 return suite; 46 } 47 48 50 protected Iterable <IteratorDescription> createDescriptions() { 51 52 List <IteratorDescription> descs = new ArrayList <IteratorDescription>(); 53 54 List <Integer > gl1 = IteratorTest.createSequentialList( 100 ); 55 List <Integer > gl2 = IteratorTest.createSequentialList( 30 ); 56 List <Integer > gl3 = IteratorTest.createSequentialList( 17 ); 57 List <Integer > gle = new ArrayList <Integer >(); 58 59 List <Integer > gl = new LinkedList <Integer >(); 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 <Iterator <Integer >> itList = new LinkedList <Iterator <Integer >>( ); 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 <Iterator <Integer >>( ); 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 106 public void testInvalidParameters() { 107 108 List <Integer > gl1 = IteratorTest.createSequentialList( 100 ); 109 List <Integer > 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 e ) { 116 } 118 119 List <Iterator <Integer >> il = new LinkedList <Iterator <Integer >>(); 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 e ) { 129 } 131 132 133 } 134 135 136 } 137 | Popular Tags |