1 17 package org.apache.commons.collections.primitives.adapters; 18 19 import java.util.Arrays ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 import java.util.ListIterator ; 23 24 import org.apache.commons.collections.BulkTest; 25 import org.apache.commons.collections.list.AbstractTestList; 26 27 31 public abstract class BaseTestList extends AbstractTestList { 32 33 36 public BaseTestList(String testName) { 37 super(testName); 38 } 39 40 43 public final void testAddAllAtIndex() { 44 List source = makeFullList(); 45 List dest = makeFullList(); 46 47 dest.addAll(1,source); 48 49 Iterator iter = dest.iterator(); 50 assertTrue(iter.hasNext()); 51 assertEquals(source.get(0),iter.next()); 52 for(int i=0;i<source.size();i++) { 53 assertTrue(iter.hasNext()); 54 assertEquals(source.get(i),iter.next()); 55 } 56 for(int i=1;i<source.size();i++) { 57 assertTrue(iter.hasNext()); 58 assertEquals(source.get(i),iter.next()); 59 } 60 assertFalse(iter.hasNext()); 61 } 62 63 66 public void testListListIteratorPreviousRemove() { 67 if (isRemoveSupported() == false) return; 68 resetFull(); 69 ListIterator it = getList().listIterator(); 70 Object zero = it.next(); 71 Object one = it.next(); 72 Object two = it.next(); 73 Object two2 = it.previous(); 74 Object one2 = it.previous(); 75 assertEquals(one, one2); 76 assertEquals(two, two2); 77 assertEquals(zero, getList().get(0)); 78 assertEquals(one, getList().get(1)); 79 assertEquals(two, getList().get(2)); 80 it.remove(); 81 assertEquals(zero, getList().get(0)); 82 assertEquals(two, getList().get(1)); 83 } 84 85 88 public BulkTest bulkTestSubList() { 89 if (getFullElements().length - 6 < 10) return null; 90 return new PrimitiveBulkTestSubList(this); 91 } 92 93 94 97 public static class PrimitiveBulkTestSubList extends BaseTestList { 98 private BaseTestList outer; 99 100 PrimitiveBulkTestSubList(BaseTestList outer) { 101 super(""); 102 this.outer = outer; 103 } 104 105 public Object [] getFullElements() { 106 List l = Arrays.asList(outer.getFullElements()); 107 return l.subList(3, l.size() - 3).toArray(); 108 } 109 public Object [] getOtherElements() { 110 return outer.getOtherElements(); 111 } 112 public boolean isAddSupported() { 113 return outer.isAddSupported(); 114 } 115 public boolean isSetSupported() { 116 return outer.isSetSupported(); 117 } 118 public boolean isRemoveSupported() { 119 return outer.isRemoveSupported(); 120 } 121 122 public List makeEmptyList() { 123 return outer.makeFullList().subList(4, 4); 124 } 125 public List makeFullList() { 126 int size = getFullElements().length; 127 return outer.makeFullList().subList(3, size - 3); 128 } 129 public void resetEmpty() { 130 outer.resetFull(); 131 this.collection = outer.getList().subList(4, 4); 132 this.confirmed = outer.getConfirmedList().subList(4, 4); 133 } 134 public void resetFull() { 135 outer.resetFull(); 136 int size = outer.confirmed.size(); 137 this.collection = outer.getList().subList(3, size - 3); 138 this.confirmed = outer.getConfirmedList().subList(3, size - 3); 139 } 140 public void verify() { 141 super.verify(); 142 outer.verify(); 143 } 144 public boolean isTestSerialization() { 145 return false; 146 } 147 150 public void testListListIteratorPreviousRemove() { 151 if (isRemoveSupported() == false) 152 return; 153 resetFull(); 154 ListIterator it = getList().listIterator(); 155 Object zero = it.next(); 156 Object one = it.next(); 157 Object two = it.next(); 158 Object two2 = it.previous(); 159 Object one2 = it.previous(); 160 assertEquals(one, one2); 161 assertEquals(two, two2); 162 assertEquals(zero, getList().get(0)); 163 assertEquals(one, getList().get(1)); 164 assertEquals(two, getList().get(2)); 165 it.remove(); 166 assertEquals(zero, getList().get(0)); 167 assertEquals(two, getList().get(1)); 168 } 169 } 170 } 171 | Popular Tags |