1 16 package org.apache.commons.collections.iterators; 17 18 import java.util.HashMap ; 19 import java.util.Map ; 20 21 import junit.framework.Test; 22 import junit.framework.TestSuite; 23 24 import org.apache.commons.collections.BidiMap; 25 import org.apache.commons.collections.MapIterator; 26 import org.apache.commons.collections.Unmodifiable; 27 import org.apache.commons.collections.bidimap.DualHashBidiMap; 28 29 36 public class TestUnmodifiableMapIterator extends AbstractTestMapIterator { 37 38 public static Test suite() { 39 return new TestSuite(TestUnmodifiableMapIterator.class); 40 } 41 42 public TestUnmodifiableMapIterator(String testName) { 43 super(testName); 44 } 45 46 public MapIterator makeEmptyMapIterator() { 47 return UnmodifiableMapIterator.decorate(new DualHashBidiMap().mapIterator()); 48 } 49 50 public MapIterator makeFullMapIterator() { 51 return UnmodifiableMapIterator.decorate(((BidiMap) getMap()).mapIterator()); 52 } 53 54 public Map getMap() { 55 Map testMap = new DualHashBidiMap(); 56 testMap.put("A", "a"); 57 testMap.put("B", "b"); 58 testMap.put("C", "c"); 59 return testMap; 60 } 61 62 public Map getConfirmedMap() { 63 Map testMap = new HashMap (); 64 testMap.put("A", "a"); 65 testMap.put("B", "b"); 66 testMap.put("C", "c"); 67 return testMap; 68 } 69 70 public boolean supportsRemove() { 71 return false; 72 } 73 74 public boolean supportsSetValue() { 75 return false; 76 } 77 78 public void testMapIterator() { 80 assertTrue(makeEmptyMapIterator() instanceof Unmodifiable); 81 } 82 83 public void testDecorateFactory() { 84 MapIterator it = makeFullMapIterator(); 85 assertSame(it, UnmodifiableMapIterator.decorate(it)); 86 87 it = ((BidiMap) getMap()).mapIterator() ; 88 assertTrue(it != UnmodifiableMapIterator.decorate(it)); 89 90 try { 91 UnmodifiableMapIterator.decorate(null); 92 fail(); 93 } catch (IllegalArgumentException ex) {} 94 } 95 96 } 97 | Popular Tags |