1 19 20 package org.netbeans.modules.j2ee.persistence.wizard.fromdb; 21 22 import java.util.Arrays ; 23 import java.util.Collections ; 24 import java.util.HashSet ; 25 import java.util.Set ; 26 import junit.framework.TestCase; 27 import org.netbeans.modules.j2ee.persistence.wizard.fromdb.TableClosure.Queue; 28 29 33 public class TableClosureQueueTest extends TestCase { 34 35 public void testInitialElements() { 36 Set <String > initial = new HashSet (Arrays.asList("a", "b")); 37 Queue<String > queue = new Queue<String >(initial); 38 Set <String > dequeued = new HashSet (); 39 while (!queue.isEmpty()) { 40 dequeued.add(queue.poll()); 41 } 42 assertNull("The poll() method should return null at the end of the queue.", queue.poll()); 43 assertEquals("Should dequeue the initial elements.", initial, dequeued); 44 } 45 46 public void testCannotAddEvenDequeuedElements() { 47 Set <String > initial = Collections.emptySet(); 48 Queue<String > queue = new Queue<String >(initial); 49 queue.offer("a"); 50 queue.offer("b"); 51 queue.offer("c"); 52 queue.offer("a"); 54 queue.offer("c"); 55 assertEquals("Should poll 'a'.", "a", queue.poll()); 56 assertEquals("Should poll 'b'.", "b", queue.poll()); 57 queue.offer("b"); 59 queue.offer("a"); 60 assertEquals("Should not poll already dequeued elements.", "c", queue.poll()); 61 assertNull("The queue should be empty.", queue.poll()); 62 } 63 } 64 | Popular Tags |