1 16 package org.apache.commons.collections.map; 17 18 import java.util.ConcurrentModificationException ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import org.apache.commons.collections.IterableMap; 23 import org.apache.commons.collections.BulkTest; 24 import org.apache.commons.collections.MapIterator; 25 import org.apache.commons.collections.iterators.AbstractTestMapIterator; 26 27 34 public abstract class AbstractTestIterableMap extends AbstractTestMap { 35 36 41 public AbstractTestIterableMap(String testName) { 42 super(testName); 43 } 44 45 public void testFailFastEntrySet() { 47 if (isRemoveSupported() == false) return; 48 resetFull(); 49 Iterator it = map.entrySet().iterator(); 50 Map.Entry val = (Map.Entry ) it.next(); 51 map.remove(val.getKey()); 52 try { 53 it.next(); 54 fail(); 55 } catch (ConcurrentModificationException ex) {} 56 57 resetFull(); 58 it = map.entrySet().iterator(); 59 it.next(); 60 map.clear(); 61 try { 62 it.next(); 63 fail(); 64 } catch (ConcurrentModificationException ex) {} 65 } 66 67 public void testFailFastKeySet() { 68 if (isRemoveSupported() == false) return; 69 resetFull(); 70 Iterator it = map.keySet().iterator(); 71 Object val = it.next(); 72 map.remove(val); 73 try { 74 it.next(); 75 fail(); 76 } catch (ConcurrentModificationException ex) {} 77 78 resetFull(); 79 it = map.keySet().iterator(); 80 it.next(); 81 map.clear(); 82 try { 83 it.next(); 84 fail(); 85 } catch (ConcurrentModificationException ex) {} 86 } 87 88 public void testFailFastValues() { 89 if (isRemoveSupported() == false) return; 90 resetFull(); 91 Iterator it = map.values().iterator(); 92 it.next(); 93 map.remove(map.keySet().iterator().next()); 94 try { 95 it.next(); 96 fail(); 97 } catch (ConcurrentModificationException ex) {} 98 99 resetFull(); 100 it = map.values().iterator(); 101 it.next(); 102 map.clear(); 103 try { 104 it.next(); 105 fail(); 106 } catch (ConcurrentModificationException ex) {} 107 } 108 109 public BulkTest bulkTestMapIterator() { 111 return new InnerTestMapIterator(); 112 } 113 114 public class InnerTestMapIterator extends AbstractTestMapIterator { 115 public InnerTestMapIterator() { 116 super("InnerTestMapIterator"); 117 } 118 119 public Object [] addSetValues() { 120 return AbstractTestIterableMap.this.getNewSampleValues(); 121 } 122 123 public boolean supportsRemove() { 124 return AbstractTestIterableMap.this.isRemoveSupported(); 125 } 126 127 public boolean isGetStructuralModify() { 128 return AbstractTestIterableMap.this.isGetStructuralModify(); 129 } 130 131 public boolean supportsSetValue() { 132 return AbstractTestIterableMap.this.isSetValueSupported(); 133 } 134 135 public MapIterator makeEmptyMapIterator() { 136 resetEmpty(); 137 return ((IterableMap) AbstractTestIterableMap.this.map).mapIterator(); 138 } 139 140 public MapIterator makeFullMapIterator() { 141 resetFull(); 142 return ((IterableMap) AbstractTestIterableMap.this.map).mapIterator(); 143 } 144 145 public Map getMap() { 146 return AbstractTestIterableMap.this.map; 148 } 149 150 public Map getConfirmedMap() { 151 return AbstractTestIterableMap.this.confirmed; 153 } 154 155 public void verify() { 156 super.verify(); 157 AbstractTestIterableMap.this.verify(); 158 } 159 } 160 161 } 168 | Popular Tags |