1 25 26 package org.archive.queue; 27 28 import java.util.NoSuchElementException ; 29 30 import org.archive.util.TmpDirTestCase; 31 32 39 public abstract class QueueTestBase extends TmpDirTestCase { 40 45 public QueueTestBase(final String testName) { 46 super(testName); 47 } 48 49 public void setUp() throws Exception { 50 super.setUp(); 51 queue = makeQueue(); 52 } 53 54 public void tearDown() { 55 if(queue != null) { 56 queue.release(); 57 } 58 } 59 60 66 protected abstract Queue<Object > makeQueue(); 67 68 71 72 73 public void testQueue() { 74 assertEquals("no items in new queue", 0, queue.length()); 75 assertTrue("queue is empty", queue.isEmpty()); 76 queue.enqueue("foo"); 77 assertEquals("now one item in queue", 1, queue.length()); 78 assertFalse("queue not empty", queue.isEmpty()); 79 } 80 81 82 public void testDequeue() { 83 assertEquals("no items in new queue", 0, queue.length()); 84 assertTrue("queue is empty", queue.isEmpty()); 85 queue.enqueue("foo"); 86 queue.enqueue("bar"); 87 queue.enqueue("baz"); 88 assertEquals("now three items in queue", 3, queue.length()); 89 assertEquals("foo dequeued", "foo", queue.dequeue()); 90 assertEquals("bar dequeued", "bar", queue.dequeue()); 91 assertEquals("baz dequeued", "baz", queue.dequeue()); 92 93 assertEquals("no items in new queue", 0, queue.length()); 94 assertTrue("queue is empty", queue.isEmpty()); 95 96 } 97 98 99 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 112 113 114 protected Queue<Object > queue; 115 } | Popular Tags |