1 16 package org.apache.commons.collections.map; 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.Factory; 25 import org.apache.commons.collections.FactoryUtils; 26 27 36 public class TestLazyMap extends AbstractTestMap { 37 38 protected static final Factory oneFactory = FactoryUtils.constantFactory("One"); 39 protected static final Factory nullFactory = FactoryUtils.nullFactory(); 40 41 public TestLazyMap(String testName) { 42 super(testName); 43 } 44 45 public static Test suite() { 46 return new TestSuite(TestLazyMap.class); 47 } 48 49 public static void main(String args[]) { 50 String [] testCaseName = { TestLazyMap.class.getName()}; 51 junit.textui.TestRunner.main(testCaseName); 52 } 53 54 protected Map decorateMap(Map map, Factory factory) { 56 return LazyMap.decorate(map, factory); 57 } 58 59 public Map makeEmptyMap() { 60 return decorateMap(new HashMap (), nullFactory); 61 } 62 63 protected Map makeTestMap(Factory factory) { 64 return decorateMap(new HashMap (), factory); 65 } 66 67 public void testMapGet() { 69 Map map = makeTestMap(oneFactory); 70 assertEquals(0, map.size()); 71 String s1 = (String ) map.get("Five"); 72 assertEquals("One", s1); 73 assertEquals(1, map.size()); 74 String s2 = (String ) map.get(new String (new char[] {'F','i','v','e'})); 75 assertEquals("One", s2); 76 assertEquals(1, map.size()); 77 assertSame(s1, s2); 78 79 map = makeTestMap(nullFactory); 80 Object o = map.get("Five"); 81 assertEquals(null,o); 82 assertEquals(1, map.size()); 83 84 } 85 86 public String getCompatibilityVersion() { 87 return "3.1"; 88 } 89 90 } | Popular Tags |