1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.struts.faces.util;
20
21
22 import java.util.Collections;
23 import java.util.Locale;
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
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
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 name) {
64
65 super(name);
66
67 }
68
69
70
71
72
73 /***
74 * <p>Set up instance variables required by this test case.</p>
75 */
76 public void setUp() throws Exception {
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 {
100
101 map = null;
102 resources = null;
103
104 }
105
106
107
108
109
110 /***
111 * <p>Test the <code>containsKey()</code> method.</p>
112 */
113 public void testContainsKey() throws Exception {
114
115
116 assertTrue(map.containsKey("foo"));
117 assertTrue(map.containsKey("bar"));
118 assertTrue(map.containsKey("baz"));
119
120
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 {
130
131
132 assertEquals("This is foo", (String) map.get("foo"));
133 assertEquals("And this is bar", (String) map.get("bar"));
134 assertEquals("We also have baz", (String) map.get("baz"));
135
136
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 {
146
147
148 try {
149 map.clear();
150 fail("clear() should have thrown UnsupportedOperationException");
151 } catch (UnsupportedOperationException e) {
152 ;
153 }
154
155
156 try {
157 map.containsValue("foo");
158 fail("containsValue() should have thrown UnsupportedOperationException");
159 } catch (UnsupportedOperationException e) {
160 ;
161 }
162
163
164 try {
165 map.entrySet();
166 fail("entrySet() should have thrown UnsupportedOperationException");
167 } catch (UnsupportedOperationException e) {
168 ;
169 }
170
171
172 try {
173 map.keySet();
174 fail("keySet() should have thrown UnsupportedOperationException");
175 } catch (UnsupportedOperationException e) {
176 ;
177 }
178
179
180 try {
181 map.put("foo", "bar");
182 fail("put() should have thrown UnsupportedOperationException");
183 } catch (UnsupportedOperationException e) {
184 ;
185 }
186
187
188 try {
189 map.putAll(Collections.EMPTY_MAP);
190 fail("putAll() should have thrown UnsupportedOperationException");
191 } catch (UnsupportedOperationException e) {
192 ;
193 }
194
195
196 try {
197 map.remove("foo");
198 fail("remove() should have thrown UnsupportedOperationException");
199 } catch (UnsupportedOperationException e) {
200 ;
201 }
202
203
204 try {
205 map.size();
206 fail("size() should have thrown UnsupportedOperationException");
207 } catch (UnsupportedOperationException e) {
208 ;
209 }
210
211
212 try {
213 map.values();
214 fail("values() should have thrown UnsupportedOperationException");
215 } catch (UnsupportedOperationException e) {
216 ;
217 }
218
219 }
220
221
222 }