1 16 package org.apache.commons.collections.map; 17 18 import java.util.ArrayList ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 import junit.framework.Test; 23 24 import org.apache.commons.collections.BulkTest; 25 import org.apache.commons.collections.MapIterator; 26 import org.apache.commons.collections.list.AbstractTestList; 27 28 38 public class TestListOrderedMap2 extends AbstractTestOrderedMap { 39 40 public TestListOrderedMap2(String testName) { 41 super(testName); 42 } 43 44 public static Test suite() { 45 return BulkTest.makeSuite(TestListOrderedMap2.class); 46 } 47 48 public static void main(String args[]) { 49 String [] testCaseName = { TestListOrderedMap2.class.getName()}; 50 junit.textui.TestRunner.main(testCaseName); 51 } 52 53 public Map makeEmptyMap() { 54 return new ListOrderedMap(); 55 } 56 57 public void testGetByIndex() { 59 resetEmpty(); 60 ListOrderedMap lom = (ListOrderedMap) map; 61 try { 62 lom.get(0); 63 } catch (IndexOutOfBoundsException ex) {} 64 try { 65 lom.get(-1); 66 } catch (IndexOutOfBoundsException ex) {} 67 68 resetFull(); 69 lom = (ListOrderedMap) map; 70 try { 71 lom.get(-1); 72 } catch (IndexOutOfBoundsException ex) {} 73 try { 74 lom.get(lom.size()); 75 } catch (IndexOutOfBoundsException ex) {} 76 77 int i = 0; 78 for (MapIterator it = lom.mapIterator(); it.hasNext(); i++) { 79 assertSame(it.next(), lom.get(i)); 80 } 81 } 82 83 public void testGetValueByIndex() { 84 resetEmpty(); 85 ListOrderedMap lom = (ListOrderedMap) map; 86 try { 87 lom.getValue(0); 88 } catch (IndexOutOfBoundsException ex) {} 89 try { 90 lom.getValue(-1); 91 } catch (IndexOutOfBoundsException ex) {} 92 93 resetFull(); 94 lom = (ListOrderedMap) map; 95 try { 96 lom.getValue(-1); 97 } catch (IndexOutOfBoundsException ex) {} 98 try { 99 lom.getValue(lom.size()); 100 } catch (IndexOutOfBoundsException ex) {} 101 102 int i = 0; 103 for (MapIterator it = lom.mapIterator(); it.hasNext(); i++) { 104 it.next(); 105 assertSame(it.getValue(), lom.getValue(i)); 106 } 107 } 108 109 public void testIndexOf() { 110 resetEmpty(); 111 ListOrderedMap lom = (ListOrderedMap) map; 112 assertEquals(-1, lom.indexOf(getOtherKeys())); 113 114 resetFull(); 115 lom = (ListOrderedMap) map; 116 List list = new ArrayList (); 117 for (MapIterator it = lom.mapIterator(); it.hasNext();) { 118 list.add(it.next()); 119 } 120 for (int i = 0; i < list.size(); i++) { 121 assertEquals(i, lom.indexOf(list.get(i))); 122 } 123 } 124 125 public void testRemoveByIndex() { 126 resetEmpty(); 127 ListOrderedMap lom = (ListOrderedMap) map; 128 try { 129 lom.remove(0); 130 } catch (IndexOutOfBoundsException ex) {} 131 try { 132 lom.remove(-1); 133 } catch (IndexOutOfBoundsException ex) {} 134 135 resetFull(); 136 lom = (ListOrderedMap) map; 137 try { 138 lom.remove(-1); 139 } catch (IndexOutOfBoundsException ex) {} 140 try { 141 lom.remove(lom.size()); 142 } catch (IndexOutOfBoundsException ex) {} 143 144 List list = new ArrayList (); 145 for (MapIterator it = lom.mapIterator(); it.hasNext();) { 146 list.add(it.next()); 147 } 148 for (int i = 0; i < list.size(); i++) { 149 Object key = list.get(i); 150 Object value = lom.get(key); 151 assertEquals(value, lom.remove(i)); 152 list.remove(i); 153 assertEquals(false, lom.containsKey(key)); 154 } 155 } 156 157 public BulkTest bulkTestListView() { 158 return new TestListView(); 159 } 160 161 public class TestListView extends AbstractTestList { 162 163 TestListView() { 164 super("TestListView"); 165 } 166 167 public List makeEmptyList() { 168 return ((ListOrderedMap) TestListOrderedMap2.this.makeEmptyMap()).asList(); 169 } 170 171 public List makeFullList() { 172 return ((ListOrderedMap) TestListOrderedMap2.this.makeFullMap()).asList(); 173 } 174 175 public Object [] getFullElements() { 176 return TestListOrderedMap2.this.getSampleKeys(); 177 } 178 public boolean isAddSupported() { 179 return false; 180 } 181 public boolean isRemoveSupported() { 182 return false; 183 } 184 public boolean isSetSupported() { 185 return false; 186 } 187 public boolean isNullSupported() { 188 return TestListOrderedMap2.this.isAllowNullKey(); 189 } 190 public boolean isTestSerialization() { 191 return false; 192 } 193 } 194 195 public String getCompatibilityVersion() { 196 return "3.1"; 197 } 198 199 } 210 | Popular Tags |