KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > faces > util > MessagesMapTestCase


1 /*
2  * Copyright 2002,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  * $Id: MessagesMapTestCase.java 155883 2005-03-02 06:03:13Z jmitchell $
17  */

18
19 package org.apache.struts.faces.util;
20
21
22 import java.util.Collections JavaDoc;
23 import java.util.Locale JavaDoc;
24
25 import junit.framework.Test;
26 import junit.framework.TestCase;
27 import junit.framework.TestSuite;
28
29 import org.apache.struts.util.MessageResources;
30
31
32 /**
33  * <p>Unit tests for <code>MessagesMap</code>.</p>
34  */

35
36 public class MessagesMapTestCase extends TestCase {
37
38
39     // ------------------------------------------------------ Instance Variables
40

41
42     /**
43      * <p>The <code>MessagesMap</code> instance to be tested.</p>
44      */

45     protected MessagesMap map = null;
46
47
48     /**
49      * <p>The <code>MessageResources</code> instance containing the messages
50      * used for testing.</p>
51      */

52     protected MessageResources resources = null;
53
54
55     // ------------------------------------------------------------ Constructors
56

57
58     /**
59      * <p>Construct a new instance of this test case.</p>
60      *
61      * @param name Name of the test case
62      */

63     public MessagesMapTestCase(String JavaDoc name) {
64
65         super(name);
66
67     }
68
69
70     // ---------------------------------------------------- Overall Test Methods
71

72
73     /**
74      * <p>Set up instance variables required by this test case.</p>
75      */

76     public void setUp() throws Exception JavaDoc {
77
78         resources =
79             MessageResources.getMessageResources
80             ("org.apache.struts.faces.util.Bundle");
81         map = new MessagesMap(resources, Locale.getDefault());
82
83     }
84
85
86     /**
87      * <p>Return the tests included in this test suite.</p>
88      */

89     public static Test suite() {
90
91         return new TestSuite(MessagesMapTestCase.class);
92
93     }
94
95
96     /**
97      * <p>Tear down instance variables required by this test case.</p>
98      */

99     public void teaDown() throws Exception JavaDoc {
100
101         map = null;
102         resources = null;
103
104     }
105
106
107     // -------------------------------------------------- Individal Test Methods
108

109
110     /**
111      * <p>Test the <code>containsKey()</code> method.</p>
112      */

113     public void testContainsKey() throws Exception JavaDoc {
114
115         // Positive tests
116
assertTrue(map.containsKey("foo"));
117         assertTrue(map.containsKey("bar"));
118         assertTrue(map.containsKey("baz"));
119
120         // Negative tests
121
assertTrue(!map.containsKey("bop"));
122
123     }
124
125
126     /**
127      * <p>Test the <code>get()</code> method.</p>
128      */

129     public void testGet() throws Exception JavaDoc {
130
131         // Positive tests
132
assertEquals("This is foo", (String JavaDoc) map.get("foo"));
133         assertEquals("And this is bar", (String JavaDoc) map.get("bar"));
134         assertEquals("We also have baz", (String JavaDoc) map.get("baz"));
135
136         // Negative tests
137
assertNull(map.get("bop"));
138
139     }
140
141
142     /**
143      * <p>Test a pristine instance, and all unsupported methods.</p>
144      */

145     public void testPristine() throws Exception JavaDoc {
146
147         // clear()
148
try {
149             map.clear();
150             fail("clear() should have thrown UnsupportedOperationException");
151         } catch (UnsupportedOperationException JavaDoc e) {
152             ; // Expected result
153
}
154
155         // containsValue()
156
try {
157             map.containsValue("foo");
158             fail("containsValue() should have thrown UnsupportedOperationException");
159         } catch (UnsupportedOperationException JavaDoc e) {
160             ; // Expected result
161
}
162
163         // entrySet()
164
try {
165             map.entrySet();
166             fail("entrySet() should have thrown UnsupportedOperationException");
167         } catch (UnsupportedOperationException JavaDoc e) {
168             ; // Expected result
169
}
170
171         // keySet()
172
try {
173             map.keySet();
174             fail("keySet() should have thrown UnsupportedOperationException");
175         } catch (UnsupportedOperationException JavaDoc e) {
176             ; // Expected result
177
}
178
179         // put()
180
try {
181             map.put("foo", "bar");
182             fail("put() should have thrown UnsupportedOperationException");
183         } catch (UnsupportedOperationException JavaDoc e) {
184             ; // Expected result
185
}
186
187         // putAll()
188
try {
189             map.putAll(Collections.EMPTY_MAP);
190             fail("putAll() should have thrown UnsupportedOperationException");
191         } catch (UnsupportedOperationException JavaDoc e) {
192             ; // Expected result
193
}
194
195         // remove()
196
try {
197             map.remove("foo");
198             fail("remove() should have thrown UnsupportedOperationException");
199         } catch (UnsupportedOperationException JavaDoc e) {
200             ; // Expected result
201
}
202
203         // size()
204
try {
205             map.size();
206             fail("size() should have thrown UnsupportedOperationException");
207         } catch (UnsupportedOperationException JavaDoc e) {
208             ; // Expected result
209
}
210
211         // size()
212
try {
213             map.values();
214             fail("values() should have thrown UnsupportedOperationException");
215         } catch (UnsupportedOperationException JavaDoc e) {
216             ; // Expected result
217
}
218
219     }
220
221
222 }
223
Popular Tags