01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: TestSelectResourceBundle.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.site;
09:
10: import java.util.Enumeration;
11: import java.util.HashMap;
12: import junit.framework.TestCase;
13:
14: public class TestSelectResourceBundle extends TestCase {
15: public TestSelectResourceBundle(String name) {
16: super (name);
17: }
18:
19: public void testIllegalArguments() {
20: try {
21: new SelectResourceBundle(null,
22: new HashMap<String, String>());
23: fail();
24: } catch (IllegalArgumentException e) {
25: assertNotNull(e);
26: }
27:
28: try {
29: new SelectResourceBundle("property", null);
30: fail();
31: } catch (IllegalArgumentException e) {
32: assertNotNull(e);
33: }
34: }
35:
36: public void testInstantiation() {
37: HashMap<String, String> map = new HashMap<String, String>();
38: map.put("key1", "value1");
39: map.put("key2", "value2");
40: map.put("key3", "value3");
41:
42: SelectResourceBundle resource_bundle = new SelectResourceBundle(
43: "myProperty", map);
44: Enumeration<String> keys_enum = resource_bundle.getKeys();
45: int count = 0;
46: while (keys_enum.hasMoreElements()) {
47: count++;
48:
49: String key = keys_enum.nextElement();
50: assertTrue(key.equals("myProperty:key1")
51: || key.equals("myProperty:key2")
52: || key.equals("myProperty:key3"));
53: }
54: assertEquals(3, count);
55:
56: assertEquals(resource_bundle.getObject("myProperty:key1"),
57: "value1");
58: assertEquals(resource_bundle.getObject("myProperty:key2"),
59: "value2");
60: assertEquals(resource_bundle.getObject("myProperty:key3"),
61: "value3");
62: }
63: }
|