KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > commons > collections > map > TestLazyMap


1 /*
2  * Copyright 2003-2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.commons.collections.map;
17
18 import java.util.HashMap JavaDoc;
19 import java.util.Map JavaDoc;
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 /**
28  * Extension of {@link TestMap} for exercising the
29  * {@link LazyMap} implementation.
30  *
31  * @since Commons Collections 3.0
32  * @version $Revision: 1.7 $ $Date: 2004/04/09 09:39:16 $
33  *
34  * @author Phil Steitz
35  */

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 JavaDoc 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 JavaDoc args[]) {
50         String JavaDoc[] testCaseName = { TestLazyMap.class.getName()};
51         junit.textui.TestRunner.main(testCaseName);
52     }
53
54     //-----------------------------------------------------------------------
55
protected Map JavaDoc decorateMap(Map JavaDoc map, Factory factory) {
56         return LazyMap.decorate(map, factory);
57     }
58     
59     public Map JavaDoc makeEmptyMap() {
60         return decorateMap(new HashMap JavaDoc(), nullFactory);
61     }
62     
63     protected Map JavaDoc makeTestMap(Factory factory) {
64         return decorateMap(new HashMap JavaDoc(), factory);
65     }
66
67     //-----------------------------------------------------------------------
68
public void testMapGet() {
69         Map JavaDoc map = makeTestMap(oneFactory);
70         assertEquals(0, map.size());
71         String JavaDoc s1 = (String JavaDoc) map.get("Five");
72         assertEquals("One", s1);
73         assertEquals(1, map.size());
74         String JavaDoc s2 = (String JavaDoc) map.get(new String JavaDoc(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 JavaDoc o = map.get("Five");
81         assertEquals(null,o);
82         assertEquals(1, map.size());
83         
84     }
85     
86     public String JavaDoc getCompatibilityVersion() {
87         return "3.1";
88     }
89
90 // public void testCreate() throws Exception {
91
// resetEmpty();
92
// writeExternalFormToDisk(
93
// (java.io.Serializable) map,
94
// "D:/dev/collections/data/test/LazyMap.emptyCollection.version3.1.obj");
95
// resetFull();
96
// writeExternalFormToDisk(
97
// (java.io.Serializable) map,
98
// "D:/dev/collections/data/test/LazyMap.fullCollection.version3.1.obj");
99
// }
100
}
Popular Tags