KickJava   Java API By Example, From Geeks To Geeks.

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


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.Unmodifiable;
25
26 /**
27  * Extension of {@link AbstractTestMap} for exercising the
28  * {@link UnmodifiableMap} implementation.
29  *
30  * @since Commons Collections 3.0
31  * @version $Revision: 1.10 $ $Date: 2004/04/09 10:46:32 $
32  *
33  * @author Phil Steitz
34  */

35 public class TestUnmodifiableMap extends AbstractTestIterableMap{
36     
37     public TestUnmodifiableMap(String JavaDoc testName) {
38         super(testName);
39     }
40     
41     public static Test suite() {
42         return new TestSuite(TestUnmodifiableMap.class);
43     }
44     
45     public static void main(String JavaDoc args[]) {
46         String JavaDoc[] testCaseName = { TestUnmodifiableMap.class.getName()};
47         junit.textui.TestRunner.main(testCaseName);
48     }
49     
50     //-------------------------------------------------------------------
51

52     public Map JavaDoc makeEmptyMap() {
53         return UnmodifiableMap.decorate(new HashMap JavaDoc());
54     }
55     
56     public boolean isPutChangeSupported() {
57         return false;
58     }
59     
60     public boolean isPutAddSupported() {
61         return false;
62     }
63     
64     public boolean isRemoveSupported() {
65         return false;
66     }
67     
68     public Map JavaDoc makeFullMap() {
69         Map JavaDoc m = new HashMap JavaDoc();
70         addSampleMappings(m);
71         return UnmodifiableMap.decorate(m);
72     }
73     
74     //-----------------------------------------------------------------------
75
public void testUnmodifiable() {
76         assertTrue(makeEmptyMap() instanceof Unmodifiable);
77         assertTrue(makeFullMap() instanceof Unmodifiable);
78     }
79     
80     public void testDecorateFactory() {
81         Map JavaDoc map = makeFullMap();
82         assertSame(map, UnmodifiableMap.decorate(map));
83         
84         try {
85             UnmodifiableMap.decorate(null);
86             fail();
87         } catch (IllegalArgumentException JavaDoc ex) {}
88     }
89
90     public String JavaDoc getCompatibilityVersion() {
91         return "3.1";
92     }
93
94 // public void testCreate() throws Exception {
95
// resetEmpty();
96
// writeExternalFormToDisk(
97
// (java.io.Serializable) map,
98
// "D:/dev/collections/data/test/UnmodifiableMap.emptyCollection.version3.1.obj");
99
// resetFull();
100
// writeExternalFormToDisk(
101
// (java.io.Serializable) map,
102
// "D:/dev/collections/data/test/UnmodifiableMap.fullCollection.version3.1.obj");
103
// }
104
}
Popular Tags