1 17 package org.apache.commons.collections.primitives; 18 19 import junit.framework.Test; 20 import junit.framework.TestSuite; 21 22 import org.apache.commons.collections.BulkTest; 23 24 28 public class TestArrayByteList extends TestByteList { 29 30 33 public TestArrayByteList(String testName) { 34 super(testName); 35 } 36 37 public static Test suite() { 38 TestSuite suite = BulkTest.makeSuite(TestArrayByteList.class); 39 return suite; 40 } 41 42 45 protected ByteList makeEmptyByteList() { 46 return new ArrayByteList(); 47 } 48 49 public String [] ignoredTests() { 50 return new String [] { 52 "TestArrayByteList.bulkTestSubList.testFullListSerialization", 53 "TestArrayByteList.bulkTestSubList.testEmptyListSerialization", 54 "TestArrayByteList.bulkTestSubList.testCanonicalEmptyCollectionExists", 55 "TestArrayByteList.bulkTestSubList.testCanonicalFullCollectionExists", 56 "TestArrayByteList.bulkTestSubList.testEmptyListCompatibility", 57 "TestArrayByteList.bulkTestSubList.testFullListCompatibility", 58 "TestArrayByteList.bulkTestSubList.testSerializeDeserializeThenCompare", 59 "TestArrayByteList.bulkTestSubList.testSimpleSerialization" 60 }; 61 } 62 63 66 67 public void testCanonicalEmptyCollectionExists() { 68 } 71 72 public void testCanonicalFullCollectionExists() { 73 } 76 77 public void testEmptyListCompatibility() { 78 } 81 82 public void testFullListCompatibility() { 83 } 86 87 public void testAddGetLargeValues() { 88 ByteList list = new ArrayByteList(); 89 for (int i = 0; i < 1000; i++) { 90 byte value = ((byte) (Byte.MAX_VALUE)); 91 value -= i; 92 list.add(value); 93 } 94 for (int i = 0; i < 1000; i++) { 95 byte value = ((byte) (Byte.MAX_VALUE)); 96 value -= i; 97 assertEquals(value, list.get(i)); 98 } 99 } 100 101 public void testZeroInitialCapacityIsValid() { 102 assertNotNull(new ArrayByteList(0)); 103 } 104 105 public void testNegativeInitialCapacityIsInvalid() { 106 try { 107 new ArrayByteList(-1); 108 fail("Expected IllegalArgumentException"); 109 } catch(IllegalArgumentException e) { 110 } 112 } 113 114 public void testCopyConstructor() { 115 ArrayByteList expected = new ArrayByteList(); 116 for(int i=0;i<10;i++) { 117 expected.add((byte)i); 118 } 119 ArrayByteList list = new ArrayByteList(expected); 120 assertEquals(10,list.size()); 121 assertEquals(expected,list); 122 } 123 124 public void testCopyConstructorWithNull() { 125 try { 126 new ArrayByteList((ByteCollection) null); 127 fail("Expected NullPointerException"); 128 } catch(NullPointerException e) { 129 } 131 } 132 133 public void testArrayConstructor() { 134 ArrayByteList expected = new ArrayByteList(); 135 for (int i = 0; i < 10; i++) { 136 expected.add((byte) i); 137 } 138 ArrayByteList list = new ArrayByteList(expected.toArray()); 139 assertEquals(10, list.size()); 140 assertEquals(expected, list); 141 } 142 143 public void testArrayConstructorWithNull() { 144 try { 145 new ArrayByteList((byte[]) null); 146 fail("Expected NullPointerException"); 147 } catch (NullPointerException e) { 148 } 150 } 151 152 153 public void testTrimToSize() { 154 ArrayByteList list = new ArrayByteList(); 155 for(int j=0;j<3;j++) { 156 assertTrue(list.isEmpty()); 157 158 list.trimToSize(); 159 160 assertTrue(list.isEmpty()); 161 162 for(int i=0;i<10;i++) { 163 list.add((byte)i); 164 } 165 166 for(int i=0;i<10;i++) { 167 assertEquals((byte)i,list.get(i)); 168 } 169 170 list.trimToSize(); 171 172 for(int i=0;i<10;i++) { 173 assertEquals((byte)i,list.get(i)); 174 } 175 176 for(int i=0;i<10;i+=2) { 177 list.removeElement((byte)i); 178 } 179 180 for(int i=0;i<5;i++) { 181 assertEquals((byte)(2*i)+1,list.get(i)); 182 } 183 184 list.trimToSize(); 185 186 for(int i=0;i<5;i++) { 187 assertEquals((byte)(2*i)+1,list.get(i)); 188 } 189 190 list.trimToSize(); 191 192 for(int i=0;i<5;i++) { 193 assertEquals((byte)(2*i)+1,list.get(i)); 194 } 195 196 list.clear(); 197 } 198 } 199 200 } 201 | Popular Tags |