1 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 35 36 public class MessagesMapTestCase extends TestCase { 37 38 39 41 42 45 protected MessagesMap map = null; 46 47 48 52 protected MessageResources resources = null; 53 54 55 57 58 63 public MessagesMapTestCase(String name) { 64 65 super(name); 66 67 } 68 69 70 72 73 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 89 public static Test suite() { 90 91 return new TestSuite(MessagesMapTestCase.class); 92 93 } 94 95 96 99 public void teaDown() throws Exception { 100 101 map = null; 102 resources = null; 103 104 } 105 106 107 109 110 113 public void testContainsKey() throws Exception { 114 115 assertTrue(map.containsKey("foo")); 117 assertTrue(map.containsKey("bar")); 118 assertTrue(map.containsKey("baz")); 119 120 assertTrue(!map.containsKey("bop")); 122 123 } 124 125 126 129 public void testGet() throws Exception { 130 131 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 assertNull(map.get("bop")); 138 139 } 140 141 142 145 public void testPristine() throws Exception { 146 147 try { 149 map.clear(); 150 fail("clear() should have thrown UnsupportedOperationException"); 151 } catch (UnsupportedOperationException e) { 152 ; } 154 155 try { 157 map.containsValue("foo"); 158 fail("containsValue() should have thrown UnsupportedOperationException"); 159 } catch (UnsupportedOperationException e) { 160 ; } 162 163 try { 165 map.entrySet(); 166 fail("entrySet() should have thrown UnsupportedOperationException"); 167 } catch (UnsupportedOperationException e) { 168 ; } 170 171 try { 173 map.keySet(); 174 fail("keySet() should have thrown UnsupportedOperationException"); 175 } catch (UnsupportedOperationException e) { 176 ; } 178 179 try { 181 map.put("foo", "bar"); 182 fail("put() should have thrown UnsupportedOperationException"); 183 } catch (UnsupportedOperationException e) { 184 ; } 186 187 try { 189 map.putAll(Collections.EMPTY_MAP); 190 fail("putAll() should have thrown UnsupportedOperationException"); 191 } catch (UnsupportedOperationException e) { 192 ; } 194 195 try { 197 map.remove("foo"); 198 fail("remove() should have thrown UnsupportedOperationException"); 199 } catch (UnsupportedOperationException e) { 200 ; } 202 203 try { 205 map.size(); 206 fail("size() should have thrown UnsupportedOperationException"); 207 } catch (UnsupportedOperationException e) { 208 ; } 210 211 try { 213 map.values(); 214 fail("values() should have thrown UnsupportedOperationException"); 215 } catch (UnsupportedOperationException e) { 216 ; } 218 219 } 220 221 222 } 223 | Popular Tags |