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 import org.netbeans.modules.java.source.util.IteratorTest.IteratorDescription; 27 28 32 public class TranslatingIteratorTest extends IteratorTest { 33 34 public TranslatingIteratorTest(String testName) { 35 super(testName); 36 } 37 38 protected void setUp() throws Exception { 39 } 40 41 protected void tearDown() throws Exception { 42 } 43 44 public static Test suite() { 45 TestSuite suite = new TestSuite(TranslatingIteratorTest.class); 46 return suite; 47 } 48 49 51 protected Iterable <IteratorDescription> createDescriptions() { 52 53 List <IteratorDescription> descs = new ArrayList <IteratorDescription>(); 54 55 List <Integer > gl = IteratorTest.createSequentialList( 100 ); 56 List <String > sl = new LinkedList (); 57 for( Integer 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 72 public void testInvalidParameters() { 73 74 try { 75 Iterators.translating( (Iterator )null, Integer2TextFactory.INSTANCE ); 76 fail( "IllegalArgumentException should have been thrown, but was not."); 77 } 78 catch( IllegalArgumentException e ) { 79 } 81 82 } 83 84 85 87 public static class Integer2TextFactory implements Factory<String ,Integer > { 88 89 public static Factory<String ,Integer > INSTANCE = new Integer2TextFactory(); 90 91 private Integer2TextFactory() {} 93 public String create(Integer parameter) { 94 return parameter.toString(); 95 } 96 97 } 98 99 } 100 101 102 | Popular Tags |