01: /*
02: (c) Copyright 2002, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
03: [See end of file]
04: $Id: TestWrappedIterator.java,v 1.9 2008/01/02 12:08:44 andy_seaborne Exp $
05: */
06:
07: package com.hp.hpl.jena.util.iterator.test;
08:
09: /**
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: public static TestSuite suite() {
22: return new TestSuite(TestWrappedIterator.class);
23: }
24:
25: public TestWrappedIterator(String name) {
26: super (name);
27: }
28:
29: public void testWrappedIterator() {
30: Iterator i = Arrays.asList(
31: new String[] { "bill", "and", "ben" }).iterator();
32: ExtendedIterator e = WrappedIterator.create(i);
33: assertTrue("wrapper has at least one element", e.hasNext());
34: assertEquals("", "bill", e.next());
35: assertTrue("wrapper has at least two elements", e.hasNext());
36: assertEquals("", "and", e.next());
37: assertTrue("wrapper has at least three elements", e.hasNext());
38: assertEquals("", "ben", e.next());
39: assertFalse("wrapper is now empty", e.hasNext());
40: }
41:
42: public void testUnwrapExtendedIterator() {
43: ExtendedIterator i = graphWith("a R b").find(Triple.ANY);
44: assertSame(i, WrappedIterator.create(i));
45: }
46:
47: public void testWrappedNoRemove() {
48: Iterator base = nodeSet("a b c").iterator();
49: base.next();
50: base.remove();
51: ExtendedIterator wrapped = WrappedIterator.createNoRemove(base);
52: wrapped.next();
53: try {
54: wrapped.remove();
55: fail("wrapped-no-remove iterator should deny .remove()");
56: } catch (UnsupportedOperationException e) {
57: pass();
58: }
59: }
60: }
61:
62: /*
63: (c) Copyright 2002, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
64: All rights reserved.
65:
66: Redistribution and use in source and binary forms, with or without
67: modification, are permitted provided that the following conditions
68: are met:
69:
70: 1. Redistributions of source code must retain the above copyright
71: notice, this list of conditions and the following disclaimer.
72:
73: 2. Redistributions in binary form must reproduce the above copyright
74: notice, this list of conditions and the following disclaimer in the
75: documentation and/or other materials provided with the distribution.
76:
77: 3. The name of the author may not be used to endorse or promote products
78: derived from this software without specific prior written permission.
79:
80: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
81: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
82: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
83: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
84: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
85: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
86: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
87: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
88: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
89: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
90: */
|