01: package org.objectweb.celtix.tools.common;
02:
03: import java.util.*;
04:
05: import junit.framework.TestCase;
06:
07: public class ProcessorEnvironmentTest extends TestCase {
08: public void testGet() {
09: Map<String, Object> map = new HashMap<String, Object>();
10: map.put("k1", "v1");
11: ProcessorEnvironment env = new ProcessorEnvironment();
12: env.setParameters(map);
13: String value = (String) env.get("k1");
14: assertEquals("v1", value);
15: }
16:
17: public void testPut() {
18: Map<String, Object> map = new HashMap<String, Object>();
19: map.put("k1", "v1");
20: ProcessorEnvironment env = new ProcessorEnvironment();
21: env.setParameters(map);
22: env.put("k2", "v2");
23: String value = (String) env.get("k2");
24: assertEquals("v2", value);
25: }
26:
27: public void testRemove() {
28: Map<String, Object> map = new HashMap<String, Object>();
29: map.put("k1", "v1");
30: ProcessorEnvironment env = new ProcessorEnvironment();
31: env.setParameters(map);
32: env.put("k2", "v2");
33: String value = (String) env.get("k2");
34: assertEquals("v2", value);
35: env.remove("k1");
36: assertNull(env.get("k1"));
37: }
38:
39: public void testContainsKey() {
40: Map<String, Object> map = new HashMap<String, Object>();
41: map.put("k1", "v1");
42: ProcessorEnvironment env = new ProcessorEnvironment();
43: env.setParameters(map);
44: assertTrue(env.containsKey("k1"));
45: }
46:
47: public void testGetDefaultValue() {
48: Map<String, Object> map = new HashMap<String, Object>();
49: map.put("k1", "v1");
50: ProcessorEnvironment env = new ProcessorEnvironment();
51: env.setParameters(map);
52:
53: String k1 = (String) env.get("k1", "v2");
54: assertEquals("v1", k1);
55: String k2 = (String) env.get("k2", "v2");
56: assertEquals("v2", k2);
57: }
58:
59: public void testOptionSet() {
60: Map<String, Object> map = new HashMap<String, Object>();
61: map.put("k1", "true");
62: ProcessorEnvironment env = new ProcessorEnvironment();
63: env.setParameters(map);
64:
65: assertTrue(env.optionSet("k1"));
66: assertFalse(env.optionSet("k2"));
67: }
68:
69: public void testGetBooleanValue() {
70: Map<String, Object> map = new HashMap<String, Object>();
71: map.put("k1", "true");
72: ProcessorEnvironment env = new ProcessorEnvironment();
73: env.setParameters(map);
74:
75: Boolean k1 = Boolean.valueOf((String) env.get("k1"));
76: assertTrue(k1);
77: Boolean k2 = Boolean.valueOf((String) env.get("k2", "true"));
78: assertTrue(k2);
79: Boolean k3 = Boolean.valueOf((String) env.get("k3", "yes"));
80: assertFalse(k3);
81: }
82:
83: }
|