1 16 package org.apache.commons.collections.list; 17 18 import java.util.ArrayList ; 19 import java.util.Arrays ; 20 import java.util.Collection ; 21 import java.util.List ; 22 23 import junit.framework.Test; 24 import junit.framework.TestSuite; 25 26 34 public class TestGrowthList extends AbstractTestList { 35 36 public TestGrowthList(String testName) { 37 super(testName); 38 } 39 40 public static Test suite() { 41 return new TestSuite(TestGrowthList.class); 42 } 43 44 public static void main(String args[]) { 45 String [] testCaseName = { TestGrowthList.class.getName()}; 46 junit.textui.TestRunner.main(testCaseName); 47 } 48 49 public List makeEmptyList() { 50 return new GrowthList(); 51 } 52 53 public List makeFullList() { 54 List list = new ArrayList (); 55 list.addAll(Arrays.asList(getFullElements())); 56 return GrowthList.decorate(list); 57 } 58 59 public void testGrowthAdd() { 61 Integer one = new Integer (1); 62 GrowthList grower = new GrowthList(); 63 assertEquals(0, grower.size()); 64 grower.add(1, one); 65 assertEquals(2, grower.size()); 66 assertEquals(null, grower.get(0)); 67 assertEquals(one, grower.get(1)); 68 } 69 70 public void testGrowthAddAll() { 71 Integer one = new Integer (1); 72 Integer two = new Integer (2); 73 Collection coll = new ArrayList (); 74 coll.add(one); 75 coll.add(two); 76 GrowthList grower = new GrowthList(); 77 assertEquals(0, grower.size()); 78 grower.addAll(1, coll); 79 assertEquals(3, grower.size()); 80 assertEquals(null, grower.get(0)); 81 assertEquals(one, grower.get(1)); 82 assertEquals(two, grower.get(2)); 83 } 84 85 public void testGrowthSet1() { 86 Integer one = new Integer (1); 87 GrowthList grower = new GrowthList(); 88 assertEquals(0, grower.size()); 89 grower.set(1, one); 90 assertEquals(2, grower.size()); 91 assertEquals(null, grower.get(0)); 92 assertEquals(one, grower.get(1)); 93 } 94 95 public void testGrowthSet2() { 96 Integer one = new Integer (1); 97 GrowthList grower = new GrowthList(); 98 assertEquals(0, grower.size()); 99 grower.set(0, one); 100 assertEquals(1, grower.size()); 101 assertEquals(one, grower.get(0)); 102 } 103 104 108 public void testListAddByIndexBoundsChecking() { 109 List list; 110 Object element = getOtherElements()[0]; 111 try { 112 list = makeEmptyList(); 113 list.add(-1, element); 114 fail("List.add should throw IndexOutOfBoundsException [-1]"); 115 } catch (IndexOutOfBoundsException e) { 116 } 118 } 119 120 123 public void testListAddByIndexBoundsChecking2() { 124 List list; 125 Object element = getOtherElements()[0]; 126 try { 127 list = makeFullList(); 128 list.add(-1, element); 129 fail("List.add should throw IndexOutOfBoundsException [-1]"); 130 } catch (IndexOutOfBoundsException e) { 131 } 133 } 134 135 138 public void testListSetByIndexBoundsChecking() { 139 List list = makeEmptyList(); 140 Object element = getOtherElements()[0]; 141 try { 142 list.set(-1, element); 143 fail("List.set should throw IndexOutOfBoundsException [-1]"); 144 } catch (IndexOutOfBoundsException e) { 145 } 147 } 148 149 152 public void testListSetByIndexBoundsChecking2() { 153 List list = makeFullList(); 154 Object element = getOtherElements()[0]; 155 try { 156 list.set(-1, element); 157 fail("List.set should throw IndexOutOfBoundsException [-1]"); 158 } catch(IndexOutOfBoundsException e) { 159 } 161 } 162 163 public String getCompatibilityVersion() { 165 return "3.2"; 166 } 167 168 175 } 176 | Popular Tags |