KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > util > iterator > test > TestWrappedIterator


1 /*
2   (c) Copyright 2002, 2004, 2005 Hewlett-Packard Development Company, LP
3   [See end of file]
4   $Id: TestWrappedIterator.java,v 1.6 2005/02/21 12:19:20 andy_seaborne Exp $
5 */

6
7 package com.hp.hpl.jena.util.iterator.test;
8
9 /**
10     test the WrappedIterator class. TODO: test _remove_, which means having
11     some fake base iterator to do the checking, and _close_, ditto.
12 */

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 JavaDoc name)
26         { super(name); }
27
28     public void testWrappedIterator()
29         {
30         Iterator i = Arrays.asList( new String JavaDoc [] {"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 JavaDoc e) { pass(); }
56         }
57     }
58
59 /*
60     (c) Copyright 2002, 2004, 2005 Hewlett-Packard Development Company, LP
61     All rights reserved.
62
63     Redistribution and use in source and binary forms, with or without
64     modification, are permitted provided that the following conditions
65     are met:
66
67     1. Redistributions of source code must retain the above copyright
68        notice, this list of conditions and the following disclaimer.
69
70     2. Redistributions in binary form must reproduce the above copyright
71        notice, this list of conditions and the following disclaimer in the
72        documentation and/or other materials provided with the distribution.
73
74     3. The name of the author may not be used to endorse or promote products
75        derived from this software without specific prior written permission.
76
77     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
78     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
79     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
80     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
81     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
82     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
83     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
84     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
85     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
86     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
87 */

88
Popular Tags