1 23 package com.sun.enterprise.management.util.misc; 24 25 26 import com.sun.appserv.management.util.misc.CircularList; 27 28 29 public class CircularListTest extends junit.framework.TestCase 30 { 31 public 32 CircularListTest() 33 { 34 } 35 36 public void 37 testCreate() 38 { 39 new CircularList<Object >( Object .class, 10 ); 40 } 41 42 43 public void 44 testCreateIllegal() 45 { 46 try 47 { 48 new CircularList<Object >( Object .class, 0 ); 49 assert( false ); 50 } 51 catch( IllegalArgumentException e ) 52 { 53 } 54 } 55 56 public void 57 testSizeAndCapacity() 58 { 59 final CircularList<Object > list = new CircularList<Object >( Object .class, 10 ); 60 61 assertEquals( 0, list.size() ); 62 assertEquals( 10, list.capacity() ); 63 } 64 65 public void 66 testClear() 67 { 68 final CircularList<Object > list = new CircularList<Object >( Object .class, 10 ); 69 70 assertEquals( 0, list.size() ); 71 72 list.add( "hello" ); 73 assertEquals( 1, list.size() ); 74 list.clear(); 75 assertEquals( 0, list.size() ); 76 77 assertEquals( 10, list.capacity() ); 78 } 79 public void 80 testAddUntilFull() 81 { 82 final int capacity = 10; 83 final CircularList<Integer > list = new CircularList<Integer >( Integer .class, capacity ); 84 assertEquals( capacity, list.capacity() ); 85 86 for( int i = 0; i < capacity; ++i ) 87 { 88 list.add( new Integer ( i ) ); 89 assert( list.size() == i + 1 ); 90 assert( ((Integer )list.get( i )).intValue() == i ); 91 } 92 assert( list.capacity() == capacity ); 93 } 94 95 public void 96 testAddPastFull() 97 { 98 final int capacity = 10; 99 final int count = capacity * 10 + 1; 100 final CircularList<Integer > list = new CircularList<Integer >( Integer .class, capacity ); 101 102 for( int i = 0; i < count; ++i ) 103 { 104 list.add( new Integer ( i ) ); 105 106 Integer value = (Integer )list.get( list.size() - 1 ); 107 assertEquals( i, value.intValue() ); 108 109 if ( i >= capacity ) 110 { 111 value = (Integer )list.get( 0 ); 112 assertEquals( 1 + (i - capacity), value.intValue() ); 113 } 114 } 115 assert( list.capacity() == capacity ); 116 } 117 118 public void 119 testRemoveFirstLast() 120 { 121 final int capacity = 3; 122 final CircularList<String > list = new CircularList<String >( String .class, capacity ); 123 124 list.add( "hello" ); 125 list.add( "xxx" ); 126 list.add( "there" ); 127 128 assertEquals( "hello", list.removeFirst() ); 129 assertEquals( "there", list.removeLast() ); 130 assertEquals( 1, list.size() ); 131 } 132 133 134 public void 135 testRemoveFirst() 136 { 137 final int capacity = 100; 138 final CircularList<Integer > list = new CircularList<Integer >( Integer .class, capacity ); 139 140 for( int i = 0; i < capacity; ++i ) 141 { 142 list.add( new Integer ( i ) ); 143 } 144 145 for( int i = 0; i < capacity; ++i ) 146 { 147 final Integer value = (Integer )list.removeFirst(); 148 assertEquals( i, value.intValue() ); 149 } 150 } 151 152 public void 153 testSet() 154 { 155 final int capacity = 100; 156 final CircularList<Integer > list = new CircularList<Integer >( Integer .class, capacity ); 157 158 for( int i = 0; i < capacity; ++i ) 159 { 160 list.add( new Integer ( i ) ); 161 } 162 163 for( int i = 0; i < capacity; ++i ) 164 { 165 final Integer value = (Integer )list.get( i ); 166 list.set( i, value ); 167 assertEquals( value, list.get( i ) ); 168 } 169 } 170 171 public void 172 testEquals() 173 { 174 final int capacity = 2; 175 final CircularList<String > list1 = new CircularList<String >( String .class, capacity ); 176 final CircularList<String > list2 = new CircularList<String >( String .class, capacity ); 177 assert( list1.equals( list2 ) ); 178 179 list1.add( "hello" ); 180 list1.add( "there" ); 181 list2.add( "hello" ); 182 list2.add( "there" ); 183 184 assert( list1.equals( list2 ) ); 185 } 186 } 187 188 189 190 191 192 193 | Popular Tags |