1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts.faces.util;
23
24
25 import java.util.Collections;
26 import java.util.Locale;
27
28 import junit.framework.Test;
29 import junit.framework.TestCase;
30 import junit.framework.TestSuite;
31
32 import org.apache.struts.util.MessageResources;
33
34
35
36
37
38
39 public class MessagesMapTestCase extends TestCase {
40
41
42
43
44
45
46
47
48 protected MessagesMap map = null;
49
50
51
52
53
54
55 protected MessageResources resources = null;
56
57
58
59
60
61
62
63
64
65
66 public MessagesMapTestCase(String name) {
67
68 super(name);
69
70 }
71
72
73
74
75
76
77
78
79 public void setUp() throws Exception {
80
81 resources =
82 MessageResources.getMessageResources
83 ("org.apache.struts.faces.util.Bundle");
84 map = new MessagesMap(resources, Locale.getDefault());
85
86 }
87
88
89
90
91
92 public static Test suite() {
93
94 return new TestSuite(MessagesMapTestCase.class);
95
96 }
97
98
99
100
101
102 public void teaDown() throws Exception {
103
104 map = null;
105 resources = null;
106
107 }
108
109
110
111
112
113
114
115
116 public void testContainsKey() throws Exception {
117
118
119 assertTrue(map.containsKey("foo"));
120 assertTrue(map.containsKey("bar"));
121 assertTrue(map.containsKey("baz"));
122
123
124 assertTrue(!map.containsKey("bop"));
125
126 }
127
128
129
130
131
132 public void testGet() throws Exception {
133
134
135 assertEquals("This is foo", (String) map.get("foo"));
136 assertEquals("And this is bar", (String) map.get("bar"));
137 assertEquals("We also have baz", (String) map.get("baz"));
138
139
140 assertNull(map.get("bop"));
141
142 }
143
144
145
146
147
148 public void testPristine() throws Exception {
149
150
151 try {
152 map.clear();
153 fail("clear() should have thrown UnsupportedOperationException");
154 } catch (UnsupportedOperationException e) {
155 ;
156 }
157
158
159 try {
160 map.containsValue("foo");
161 fail("containsValue() should have thrown UnsupportedOperationException");
162 } catch (UnsupportedOperationException e) {
163 ;
164 }
165
166
167 try {
168 map.entrySet();
169 fail("entrySet() should have thrown UnsupportedOperationException");
170 } catch (UnsupportedOperationException e) {
171 ;
172 }
173
174
175 try {
176 map.keySet();
177 fail("keySet() should have thrown UnsupportedOperationException");
178 } catch (UnsupportedOperationException e) {
179 ;
180 }
181
182
183 try {
184 map.put("foo", "bar");
185 fail("put() should have thrown UnsupportedOperationException");
186 } catch (UnsupportedOperationException e) {
187 ;
188 }
189
190
191 try {
192 map.putAll(Collections.EMPTY_MAP);
193 fail("putAll() should have thrown UnsupportedOperationException");
194 } catch (UnsupportedOperationException e) {
195 ;
196 }
197
198
199 try {
200 map.remove("foo");
201 fail("remove() should have thrown UnsupportedOperationException");
202 } catch (UnsupportedOperationException e) {
203 ;
204 }
205
206
207 try {
208 map.size();
209 fail("size() should have thrown UnsupportedOperationException");
210 } catch (UnsupportedOperationException e) {
211 ;
212 }
213
214
215 try {
216 map.values();
217 fail("values() should have thrown UnsupportedOperationException");
218 } catch (UnsupportedOperationException e) {
219 ;
220 }
221
222 }
223
224
225 }