1 17 package org.apache.commons.collections.primitives.decorators; 18 19 import junit.framework.TestCase; 20 21 import org.apache.commons.collections.primitives.ArrayDoubleList; 22 import org.apache.commons.collections.primitives.DoubleIterator; 23 import org.apache.commons.collections.primitives.DoubleList; 24 25 29 public abstract class BaseUnmodifiableDoubleIteratorTest extends TestCase { 30 31 34 public BaseUnmodifiableDoubleIteratorTest(String testName) { 35 super(testName); 36 } 37 38 39 protected abstract DoubleIterator makeUnmodifiableDoubleIterator(); 42 43 protected DoubleIterator makeDoubleIterator() { 44 DoubleList list = new ArrayDoubleList(); 45 for(double i=0;i<10;i++) { 46 list.add(i); 47 } 48 return list.iterator(); 49 } 50 51 54 public final void testDoubleIteratorNotModifiable() { 55 DoubleIterator iter = makeUnmodifiableDoubleIterator(); 56 assertTrue(iter.hasNext()); 57 iter.next(); 58 try { 59 iter.remove(); 60 fail("Expected UnsupportedOperationException"); 61 } catch(UnsupportedOperationException e) { 62 } 64 } 65 66 public final void testIterateDoubleIterator() { 67 DoubleIterator iter = makeUnmodifiableDoubleIterator(); 68 for(DoubleIterator expected = makeDoubleIterator(); expected.hasNext(); ) { 69 assertTrue(iter.hasNext()); 70 assertEquals(expected.next(),iter.next(),(double)0); 71 } 72 assertTrue(! iter.hasNext() ); 73 } 74 75 } | Popular Tags |