1 3 package org.jgroups.tests; 4 5 6 import junit.framework.TestCase; 7 import org.jgroups.util.BoundedList; 8 9 10 public class BoundedListTest extends TestCase { 11 private BoundedList l=null; 12 13 public BoundedListTest(String name) { 14 super(name); 15 } 16 17 public void setUp() throws Exception { 18 super.setUp(); 19 l=new BoundedList(3); 20 } 21 22 23 public void tearDown() throws Exception { 24 super.tearDown(); 25 l.removeAll(); 26 l=null; 27 } 28 29 30 public void testAdd() throws Exception { 31 assertEquals(l.size(), 0); 32 l.add(new Integer (1)); 33 System.out.println(l); 34 assertEquals(l.size(), 1); 35 36 l.add(new Integer (2)); 37 System.out.println(l); 38 39 l.add(new Integer (3)); 40 System.out.println(l); 41 assertEquals(l.size(), 3); 42 43 l.add(new Integer (4)); 44 System.out.println(l); 45 assertEquals(l.size(), 3); 46 47 48 int tmp; 49 50 tmp=((Integer )l.removeFromHead()).intValue(); 51 assertEquals(tmp, 2); 52 53 tmp=((Integer )l.removeFromHead()).intValue(); 54 assertEquals(tmp, 3); 55 56 tmp=((Integer )l.removeFromHead()).intValue(); 57 assertEquals(tmp, 4); 58 } 59 60 61 public void testAddAtHead() throws Exception { 62 assertEquals(l.size(), 0); 63 l.addAtHead(new Integer (1)); 64 System.out.println(l); 65 assertEquals(l.size(), 1); 66 67 l.addAtHead(new Integer (2)); 68 System.out.println(l); 69 70 l.addAtHead(new Integer (3)); 71 System.out.println(l); 72 assertEquals(l.size(), 3); 73 74 l.addAtHead(new Integer (4)); 75 System.out.println(l); 76 assertEquals(l.size(), 3); 77 78 int tmp; 79 80 tmp=((Integer )l.removeFromHead()).intValue(); 81 assertEquals(tmp, 4); 82 83 tmp=((Integer )l.removeFromHead()).intValue(); 84 assertEquals(tmp, 3); 85 86 tmp=((Integer )l.removeFromHead()).intValue(); 87 assertEquals(tmp, 2); 88 } 89 90 91 public void testContains() throws Exception { 92 l.add("Bela"); 93 System.out.println(l); 94 95 l.add("Michelle"); 96 System.out.println(l); 97 98 l.add("Jeannette"); 99 System.out.println(l); 100 101 l.add("Nicole"); 102 System.out.println(l); 103 104 assertTrue(l.contains("Bela") == false); 105 assertTrue(l.contains("Nicole")); 106 assertTrue(l.contains("Michelle")); 107 } 108 109 public static void main(String [] args) { 110 String [] testCaseName={BoundedListTest.class.getName()}; 111 junit.textui.TestRunner.main(testCaseName); 112 } 113 114 } 115 | Popular Tags |