001: /*
002: * $Id: MessagesMapTestCase.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021:
022: package org.apache.struts.faces.util;
023:
024: import java.util.Collections;
025: import java.util.Locale;
026:
027: import junit.framework.Test;
028: import junit.framework.TestCase;
029: import junit.framework.TestSuite;
030:
031: import org.apache.struts.util.MessageResources;
032:
033: /**
034: * <p>Unit tests for <code>MessagesMap</code>.</p>
035: */
036:
037: public class MessagesMapTestCase extends TestCase {
038:
039: // ------------------------------------------------------ Instance Variables
040:
041: /**
042: * <p>The <code>MessagesMap</code> instance to be tested.</p>
043: */
044: protected MessagesMap map = null;
045:
046: /**
047: * <p>The <code>MessageResources</code> instance containing the messages
048: * used for testing.</p>
049: */
050: protected MessageResources resources = null;
051:
052: // ------------------------------------------------------------ Constructors
053:
054: /**
055: * <p>Construct a new instance of this test case.</p>
056: *
057: * @param name Name of the test case
058: */
059: public MessagesMapTestCase(String name) {
060:
061: super (name);
062:
063: }
064:
065: // ---------------------------------------------------- Overall Test Methods
066:
067: /**
068: * <p>Set up instance variables required by this test case.</p>
069: */
070: public void setUp() throws Exception {
071:
072: resources = MessageResources
073: .getMessageResources("org.apache.struts.faces.util.Bundle");
074: map = new MessagesMap(resources, Locale.getDefault());
075:
076: }
077:
078: /**
079: * <p>Return the tests included in this test suite.</p>
080: */
081: public static Test suite() {
082:
083: return new TestSuite(MessagesMapTestCase.class);
084:
085: }
086:
087: /**
088: * <p>Tear down instance variables required by this test case.</p>
089: */
090: public void teaDown() throws Exception {
091:
092: map = null;
093: resources = null;
094:
095: }
096:
097: // -------------------------------------------------- Individal Test Methods
098:
099: /**
100: * <p>Test the <code>containsKey()</code> method.</p>
101: */
102: public void testContainsKey() throws Exception {
103:
104: // Positive tests
105: assertTrue(map.containsKey("foo"));
106: assertTrue(map.containsKey("bar"));
107: assertTrue(map.containsKey("baz"));
108:
109: // Negative tests
110: assertTrue(!map.containsKey("bop"));
111:
112: }
113:
114: /**
115: * <p>Test the <code>get()</code> method.</p>
116: */
117: public void testGet() throws Exception {
118:
119: // Positive tests
120: assertEquals("This is foo", (String) map.get("foo"));
121: assertEquals("And this is bar", (String) map.get("bar"));
122: assertEquals("We also have baz", (String) map.get("baz"));
123:
124: // Negative tests
125: assertNull(map.get("bop"));
126:
127: }
128:
129: /**
130: * <p>Test a pristine instance, and all unsupported methods.</p>
131: */
132: public void testPristine() throws Exception {
133:
134: // clear()
135: try {
136: map.clear();
137: fail("clear() should have thrown UnsupportedOperationException");
138: } catch (UnsupportedOperationException e) {
139: ; // Expected result
140: }
141:
142: // containsValue()
143: try {
144: map.containsValue("foo");
145: fail("containsValue() should have thrown UnsupportedOperationException");
146: } catch (UnsupportedOperationException e) {
147: ; // Expected result
148: }
149:
150: // entrySet()
151: try {
152: map.entrySet();
153: fail("entrySet() should have thrown UnsupportedOperationException");
154: } catch (UnsupportedOperationException e) {
155: ; // Expected result
156: }
157:
158: // keySet()
159: try {
160: map.keySet();
161: fail("keySet() should have thrown UnsupportedOperationException");
162: } catch (UnsupportedOperationException e) {
163: ; // Expected result
164: }
165:
166: // put()
167: try {
168: map.put("foo", "bar");
169: fail("put() should have thrown UnsupportedOperationException");
170: } catch (UnsupportedOperationException e) {
171: ; // Expected result
172: }
173:
174: // putAll()
175: try {
176: map.putAll(Collections.EMPTY_MAP);
177: fail("putAll() should have thrown UnsupportedOperationException");
178: } catch (UnsupportedOperationException e) {
179: ; // Expected result
180: }
181:
182: // remove()
183: try {
184: map.remove("foo");
185: fail("remove() should have thrown UnsupportedOperationException");
186: } catch (UnsupportedOperationException e) {
187: ; // Expected result
188: }
189:
190: // size()
191: try {
192: map.size();
193: fail("size() should have thrown UnsupportedOperationException");
194: } catch (UnsupportedOperationException e) {
195: ; // Expected result
196: }
197:
198: // size()
199: try {
200: map.values();
201: fail("values() should have thrown UnsupportedOperationException");
202: } catch (UnsupportedOperationException e) {
203: ; // Expected result
204: }
205:
206: }
207:
208: }
|