1 17 package org.apache.commons.collections.primitives.decorators; 18 19 import junit.framework.TestCase; 20 21 import org.apache.commons.collections.primitives.ArrayLongList; 22 import org.apache.commons.collections.primitives.LongIterator; 23 import org.apache.commons.collections.primitives.LongList; 24 25 29 public abstract class BaseUnmodifiableLongIteratorTest extends TestCase { 30 31 34 public BaseUnmodifiableLongIteratorTest(String testName) { 35 super(testName); 36 } 37 38 39 protected abstract LongIterator makeUnmodifiableLongIterator(); 42 43 protected LongIterator makeLongIterator() { 44 LongList list = new ArrayLongList(); 45 for(long i=0;i<10;i++) { 46 list.add(i); 47 } 48 return list.iterator(); 49 } 50 51 54 public final void testLongIteratorNotModifiable() { 55 LongIterator iter = makeUnmodifiableLongIterator(); 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 testIterateLongIterator() { 67 LongIterator iter = makeUnmodifiableLongIterator(); 68 for(LongIterator expected = makeLongIterator(); expected.hasNext(); ) { 69 assertTrue(iter.hasNext()); 70 assertEquals(expected.next(),iter.next()); 71 } 72 assertTrue(! iter.hasNext() ); 73 } 74 75 } | Popular Tags |