1 6 7 package com.hp.hpl.jena.util.iterator.test; 8 9 13 14 import com.hp.hpl.jena.graph.Triple; 15 import com.hp.hpl.jena.graph.test.GraphTestBase; 16 import com.hp.hpl.jena.util.iterator.*; 17 import java.util.*; 18 import junit.framework.*; 19 20 public class TestWrappedIterator extends GraphTestBase 21 { 22 public static TestSuite suite() 23 { return new TestSuite( TestWrappedIterator.class ); } 24 25 public TestWrappedIterator(String name) 26 { super(name); } 27 28 public void testWrappedIterator() 29 { 30 Iterator i = Arrays.asList( new String [] {"bill", "and", "ben"} ).iterator(); 31 ExtendedIterator e = WrappedIterator.create( i ); 32 assertTrue( "wrapper has at least one element", e.hasNext() ); 33 assertEquals( "", "bill", e.next() ); 34 assertTrue( "wrapper has at least two elements", e.hasNext() ); 35 assertEquals( "", "and", e.next() ); 36 assertTrue( "wrapper has at least three elements", e.hasNext() ); 37 assertEquals( "", "ben", e.next() ); 38 assertFalse( "wrapper is now empty", e.hasNext() ); 39 } 40 41 public void testUnwrapExtendedIterator() 42 { 43 ExtendedIterator i = graphWith( "a R b" ).find( Triple.ANY ); 44 assertSame( i, WrappedIterator.create( i ) ); 45 } 46 47 public void testWrappedNoRemove() 48 { 49 Iterator base = nodeSet( "a b c" ).iterator(); 50 base.next(); 51 base.remove(); 52 ExtendedIterator wrapped = WrappedIterator.createNoRemove( base ); 53 wrapped.next(); 54 try { wrapped.remove(); fail( "wrapped-no-remove iterator should deny .remove()" ); } 55 catch (UnsupportedOperationException e) { pass(); } 56 } 57 } 58 59 88 | Popular Tags |