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