001: /*
002: * Copyright 2003-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.collections.map;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import junit.framework.Test;
022: import junit.framework.TestSuite;
023:
024: import org.apache.commons.collections.Factory;
025: import org.apache.commons.collections.FactoryUtils;
026:
027: /**
028: * Extension of {@link TestMap} for exercising the
029: * {@link LazyMap} implementation.
030: *
031: * @since Commons Collections 3.0
032: * @version $Revision: 155406 $ $Date: 2005-02-26 12:55:26 +0000 (Sat, 26 Feb 2005) $
033: *
034: * @author Phil Steitz
035: */
036: public class TestLazyMap extends AbstractTestMap {
037:
038: protected static final Factory oneFactory = FactoryUtils
039: .constantFactory("One");
040: protected static final Factory nullFactory = FactoryUtils
041: .nullFactory();
042:
043: public TestLazyMap(String testName) {
044: super (testName);
045: }
046:
047: public static Test suite() {
048: return new TestSuite(TestLazyMap.class);
049: }
050:
051: public static void main(String args[]) {
052: String[] testCaseName = { TestLazyMap.class.getName() };
053: junit.textui.TestRunner.main(testCaseName);
054: }
055:
056: //-----------------------------------------------------------------------
057: protected Map decorateMap(Map map, Factory factory) {
058: return LazyMap.decorate(map, factory);
059: }
060:
061: public Map makeEmptyMap() {
062: return decorateMap(new HashMap(), nullFactory);
063: }
064:
065: protected Map makeTestMap(Factory factory) {
066: return decorateMap(new HashMap(), factory);
067: }
068:
069: //-----------------------------------------------------------------------
070: public void testMapGet() {
071: Map map = makeTestMap(oneFactory);
072: assertEquals(0, map.size());
073: String s1 = (String) map.get("Five");
074: assertEquals("One", s1);
075: assertEquals(1, map.size());
076: String s2 = (String) map.get(new String(new char[] { 'F', 'i',
077: 'v', 'e' }));
078: assertEquals("One", s2);
079: assertEquals(1, map.size());
080: assertSame(s1, s2);
081:
082: map = makeTestMap(nullFactory);
083: Object o = map.get("Five");
084: assertEquals(null, o);
085: assertEquals(1, map.size());
086:
087: }
088:
089: public String getCompatibilityVersion() {
090: return "3.1";
091: }
092:
093: // public void testCreate() throws Exception {
094: // resetEmpty();
095: // writeExternalFormToDisk(
096: // (java.io.Serializable) map,
097: // "D:/dev/collections/data/test/LazyMap.emptyCollection.version3.1.obj");
098: // resetFull();
099: // writeExternalFormToDisk(
100: // (java.io.Serializable) map,
101: // "D:/dev/collections/data/test/LazyMap.fullCollection.version3.1.obj");
102: // }
103: }
|