001: /*
002: * $Id: TestEmptyRowIterator.java,v 1.7 2005/04/22 21:34:17 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2002-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.engine.rowiterators;
042:
043: import java.util.ArrayList;
044: import java.util.List;
045: import java.util.NoSuchElementException;
046:
047: import junit.framework.Test;
048: import junit.framework.TestSuite;
049:
050: import org.axiondb.AxionException;
051: import org.axiondb.Row;
052: import org.axiondb.RowIterator;
053: import org.axiondb.engine.rows.SimpleRow;
054:
055: /**
056: * @version $Revision: 1.7 $ $Date: 2005/04/22 21:34:17 $
057: * @author Rodney Waldhoff
058: */
059: public class TestEmptyRowIterator extends AbstractRowIteratorTest {
060:
061: //------------------------------------------------------------ Conventional
062:
063: public TestEmptyRowIterator(String testName) {
064: super (testName);
065: }
066:
067: public static Test suite() {
068: TestSuite suite = new TestSuite(TestEmptyRowIterator.class);
069: return suite;
070: }
071:
072: //---------------------------------------------------------- Abstract Impls
073:
074: public RowIterator makeRowIterator() {
075: return new EmptyRowIterator();
076: }
077:
078: public List makeRowList() {
079: return new ArrayList();
080: }
081:
082: protected int getSize() {
083: return 0;
084: }
085:
086: //------------------------------------------------------------------- Tests
087:
088: public void testEmpty() throws Exception {
089: RowIterator iter = new EmptyRowIterator();
090:
091: for (int i = 0; i < 3; i++) {
092: assertTrue(!iter.hasCurrent());
093:
094: try {
095: iter.first();
096: fail("Expected NoSuchElementException");
097: } catch (NoSuchElementException e) {
098: // expected
099: }
100:
101: try {
102: iter.last();
103: fail("Expected NoSuchElementException");
104: } catch (NoSuchElementException e) {
105: // expected
106: }
107:
108: try {
109: iter.next();
110: fail("Expected NoSuchElementException");
111: } catch (NoSuchElementException e) {
112: // expected
113: }
114:
115: try {
116: iter.next(1);
117: fail("Expected UnsupportedOperationException");
118: } catch (UnsupportedOperationException e) {
119: // expected
120: }
121:
122: try {
123: iter.previous();
124: fail("Expected NoSuchElementException");
125: } catch (NoSuchElementException e) {
126: // expected
127: }
128:
129: try {
130: iter.previous(1);
131: fail("Expected UnsupportedOperationException");
132: } catch (UnsupportedOperationException e) {
133: // expected
134: }
135:
136: assertTrue(!iter.hasNext());
137: assertTrue(!iter.hasPrevious());
138: assertTrue(iter.isEmpty());
139:
140: try {
141: iter.add(null);
142: fail("Expected UnsupportedOperationException");
143: } catch (UnsupportedOperationException e) {
144: // expected
145: }
146:
147: assertEquals(0, iter.nextIndex());
148: assertEquals(-1, iter.previousIndex());
149:
150: assertEquals(-1, iter.currentIndex());
151:
152: try {
153: iter.remove();
154: fail("Expected UnsupportedOperationException");
155: } catch (UnsupportedOperationException e) {
156: // expected
157: }
158:
159: try {
160: iter.set(null);
161: fail("Expected UnsupportedOperationException");
162: } catch (UnsupportedOperationException e) {
163: // expected
164: }
165:
166: try {
167: iter.peekNext();
168: fail("Expected NoSuchElementException");
169: } catch (NoSuchElementException e) {
170: // expected
171: }
172:
173: try {
174: iter.peekPrevious();
175: fail("Expected NoSuchElementException");
176: } catch (NoSuchElementException e) {
177: // expected
178: }
179:
180: iter.reset();
181: }
182: }
183:
184: public void testNextAfterLast() throws Exception {
185: }
186:
187: public void testPreviousBeforeFirst() throws Exception {
188: }
189:
190: public void testPeekNextAfterLast() throws Exception {
191: }
192:
193: public void testNextAndPrevious() throws Exception {
194: }
195:
196: public void testPeekPreviousBeforeFirst() throws Exception {
197: }
198:
199: public void testLazyNextprevious() throws Exception {
200: }
201:
202: public void testBase() throws Exception {
203: RowIterator rows = new BaseRowIterator() {
204: public Row current() throws NoSuchElementException {
205: return null;
206: }
207:
208: public int currentIndex() throws NoSuchElementException {
209: return 0;
210: }
211:
212: public boolean hasCurrent() {
213: return false;
214: }
215:
216: public boolean hasNext() {
217: return false;
218: }
219:
220: public boolean hasPrevious() {
221: return false;
222: }
223:
224: public Row next() throws NoSuchElementException,
225: AxionException {
226: return null;
227: }
228:
229: public int nextIndex() {
230: return 0;
231: }
232:
233: public Row previous() throws NoSuchElementException,
234: AxionException {
235: return null;
236: }
237:
238: public int previousIndex() {
239: return 0;
240: }
241:
242: public void reset() throws AxionException {
243: }
244: };
245:
246: try {
247: rows.add(new SimpleRow(1));
248: } catch (UnsupportedOperationException e) {
249: // expected
250: }
251:
252: try {
253: rows.remove();
254: } catch (UnsupportedOperationException e) {
255: // expected
256: }
257:
258: try {
259: rows.set(new SimpleRow(1));
260: } catch (UnsupportedOperationException e) {
261: // expected
262: }
263: }
264: }
|