001: /*
002: * $Id: TestIntListIteratorChain.java,v 1.1 2003/05/12 22:22:36 rwald Exp $
003: * =======================================================================
004: * Copyright (c) 2003 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb.util;
042:
043: import java.util.NoSuchElementException;
044:
045: import junit.framework.Test;
046: import junit.framework.TestCase;
047: import junit.framework.TestSuite;
048:
049: /**
050: * @version $Revision: 1.1 $ $Date: 2003/05/12 22:22:36 $
051: * @author Rodney Waldhoff
052: */
053: public class TestIntListIteratorChain extends TestCase {
054:
055: //------------------------------------------------------------ Conventional
056:
057: public TestIntListIteratorChain(String testName) {
058: super (testName);
059: }
060:
061: public static Test suite() {
062: return new TestSuite(TestIntListIteratorChain.class);
063: }
064:
065: //--------------------------------------------------------------- Lifecycle
066:
067: public void setUp() throws Exception {
068: super .setUp();
069: }
070:
071: public void tearDown() throws Exception {
072: super .tearDown();
073: }
074:
075: //------------------------------------------------------------------- Tests
076:
077: public void testEmpty() throws Exception {
078: IntListIteratorChain chain = new IntListIteratorChain();
079:
080: assertTrue(!chain.hasNext());
081: assertEquals(0, chain.nextIndex());
082: try {
083: chain.next();
084: fail("Expected NoSuchElementException");
085: } catch (NoSuchElementException e) {
086: // expected
087: }
088:
089: assertTrue(!chain.hasPrevious());
090: assertEquals(-1, chain.previousIndex());
091: try {
092: chain.previous();
093: fail("Expected NoSuchElementException");
094: } catch (NoSuchElementException e) {
095: // expected
096: }
097:
098: }
099:
100: public void testCantAddOnceIterating() throws Exception {
101: IntListIteratorChain chain = new IntListIteratorChain();
102: chain.addIterator(1);
103: assertEquals(1, chain.next());
104: try {
105: chain.addIterator(2);
106: fail("Expected IllegalStateException");
107: } catch (IllegalStateException e) {
108: // expected
109: }
110: }
111:
112: public void testSingletons() throws Exception {
113: IntListIteratorChain chain = new IntListIteratorChain();
114: chain.addIterator(1);
115: chain.addIterator(2);
116: chain.addIterator(3);
117:
118: assertTrue(!chain.hasPrevious());
119: assertTrue(chain.hasNext());
120: assertEquals(-1, chain.previousIndex());
121: assertEquals(0, chain.nextIndex());
122: assertEquals(1, chain.next());
123:
124: assertTrue(chain.hasPrevious());
125: assertTrue(chain.hasNext());
126: assertEquals(0, chain.previousIndex());
127: assertEquals(1, chain.nextIndex());
128: assertEquals(2, chain.next());
129:
130: assertTrue(chain.hasPrevious());
131: assertTrue(chain.hasNext());
132: assertEquals(1, chain.previousIndex());
133: assertEquals(2, chain.nextIndex());
134: assertEquals(3, chain.next());
135:
136: assertTrue(chain.hasPrevious());
137: assertTrue(!chain.hasNext());
138: assertEquals(2, chain.previousIndex());
139: assertEquals(3, chain.nextIndex());
140: assertEquals(3, chain.previous());
141:
142: assertTrue(chain.hasPrevious());
143: assertTrue(chain.hasNext());
144: assertEquals(1, chain.previousIndex());
145: assertEquals(2, chain.nextIndex());
146: assertEquals(2, chain.previous());
147:
148: assertTrue(chain.hasPrevious());
149: assertTrue(chain.hasNext());
150: assertEquals(0, chain.previousIndex());
151: assertEquals(1, chain.nextIndex());
152: assertEquals(1, chain.previous());
153:
154: assertTrue(!chain.hasPrevious());
155: assertTrue(chain.hasNext());
156: assertEquals(-1, chain.previousIndex());
157: assertEquals(0, chain.nextIndex());
158: }
159:
160: public void testNotModifiable() throws Exception {
161: IntListIteratorChain chain = new IntListIteratorChain();
162: chain.addIterator(1);
163: chain.addIterator(2);
164: chain.addIterator(3);
165:
166: assertTrue(chain.hasNext());
167: assertEquals(1, chain.next());
168:
169: try {
170: chain.add(4);
171: fail("Expected UnsupportedOperationException");
172: } catch (UnsupportedOperationException e) {
173: // expected
174: }
175:
176: try {
177: chain.remove();
178: fail("Expected UnsupportedOperationException");
179: } catch (UnsupportedOperationException e) {
180: // expected
181: }
182:
183: try {
184: chain.set(4);
185: fail("Expected UnsupportedOperationException");
186: } catch (UnsupportedOperationException e) {
187: // expected
188: }
189: }
190: }
|