1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.util;
20
21 import java.util.Enumeration;
22 import java.util.HashMap;
23 import java.util.Map;
24
25 import junit.framework.TestCase;
26
27
28
29
30
31 public class AbstractAttributeMapTest extends TestCase
32 {
33 private TestAttributeMap _testimpl;
34
35 @Override
36 protected void setUp() throws Exception
37 {
38 Map<String, Object> map = new HashMap<String, Object>();
39 map.put("key", "value");
40 _testimpl = new TestAttributeMap(map);
41 }
42
43
44
45
46 public void testHashCodeEquals()
47 {
48 assertEquals(_testimpl.hashCode(), _testimpl.hashCode());
49 }
50
51 public void testValues() throws Exception
52 {
53 _testimpl.put("myKey", "myValue");
54 assertTrue(_testimpl.values().contains("myValue"));
55 }
56
57 private static final class TestAttributeMap extends AbstractAttributeMap<Object>
58 {
59 private final Map<String, Object> _values;
60
61 public TestAttributeMap(Map<String, Object> values)
62 {
63 _values = values;
64 }
65
66 @Override
67 protected Object getAttribute(String key)
68 {
69 return _values.get(key);
70 }
71
72 @Override
73 protected Enumeration<String> getAttributeNames()
74 {
75 return new IteratorEnumeration<String>(_values.keySet().iterator());
76 }
77
78 @Override
79 protected void removeAttribute(String key)
80 {
81 _values.remove(key);
82 }
83
84 @Override
85 protected void setAttribute(String key, Object value)
86 {
87 _values.put(key, value);
88 }
89 }
90
91 }