001: /* QueueTestBase
002: *
003: * $Id: QueueTestBase.java 4645 2006-09-22 16:08:03Z paul_jack $
004: *
005: * Created Tue Jan 20 14:17:59 PST 2004
006: *
007: * Copyright (C) 2004 Internet Archive.
008: *
009: * This file is part of the Heritrix web crawler (crawler.archive.org).
010: *
011: * Heritrix is free software; you can redistribute it and/or modify
012: * it under the terms of the GNU Lesser Public License as published by
013: * the Free Software Foundation; either version 2.1 of the License, or
014: * any later version.
015: *
016: * Heritrix is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
019: * GNU Lesser Public License for more details.
020: *
021: * You should have received a copy of the GNU Lesser Public License
022: * along with Heritrix; if not, write to the Free Software
023: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024: */
025:
026: package org.archive.queue;
027:
028: import java.util.NoSuchElementException;
029:
030: import org.archive.util.TmpDirTestCase;
031:
032: /**
033: * JUnit test suite for Queue. It's an abstract class which is implemented by
034: * each queue implementation
035: *
036: * @author <a href="mailto:me@jamesc.net">James Casey</a>
037: * @version $Id: QueueTestBase.java 4645 2006-09-22 16:08:03Z paul_jack $
038: */
039: public abstract class QueueTestBase extends TmpDirTestCase {
040: /**
041: * Create a new PaddingStringBufferTest object
042: *
043: * @param testName the name of the test
044: */
045: public QueueTestBase(final String testName) {
046: super (testName);
047: }
048:
049: public void setUp() throws Exception {
050: super .setUp();
051: queue = makeQueue();
052: }
053:
054: public void tearDown() {
055: if (queue != null) {
056: queue.release();
057: }
058: }
059:
060: /**
061: * The abstract subclass constructor. The subclass should create an
062: * instance of the object it wishes to have tested
063: *
064: * @return the Queue object to be tested
065: */
066: protected abstract Queue<Object> makeQueue();
067:
068: /*
069: * test methods
070: */
071:
072: /** test that queue puts things on, and they stay there :) */
073: public void testQueue() {
074: assertEquals("no items in new queue", 0, queue.length());
075: assertTrue("queue is empty", queue.isEmpty());
076: queue.enqueue("foo");
077: assertEquals("now one item in queue", 1, queue.length());
078: assertFalse("queue not empty", queue.isEmpty());
079: }
080:
081: /** test that dequeue works */
082: public void testDequeue() {
083: assertEquals("no items in new queue", 0, queue.length());
084: assertTrue("queue is empty", queue.isEmpty());
085: queue.enqueue("foo");
086: queue.enqueue("bar");
087: queue.enqueue("baz");
088: assertEquals("now three items in queue", 3, queue.length());
089: assertEquals("foo dequeued", "foo", queue.dequeue());
090: assertEquals("bar dequeued", "bar", queue.dequeue());
091: assertEquals("baz dequeued", "baz", queue.dequeue());
092:
093: assertEquals("no items in new queue", 0, queue.length());
094: assertTrue("queue is empty", queue.isEmpty());
095:
096: }
097:
098: /** check what happens we dequeue on empty */
099: public void testDequeueEmptyQueue() {
100: assertTrue("queue is empty", queue.isEmpty());
101:
102: try {
103: queue.dequeue();
104: } catch (NoSuchElementException e) {
105: return;
106: }
107: fail("Expected a NoSuchElementException on dequeue of empty queue");
108: }
109:
110: /*
111: * member variables
112: */
113:
114: /** the queue object to be tested */
115: protected Queue<Object> queue;
116: }
|