View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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   * @author Mathias Broekelmann (latest modification by $Author: slessard $)
29   * @version $Revision: 699848 $ $Date: 2008-09-28 11:12:21 -0500 (Sun, 28 Sep 2008) $
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       * Test method for {@link java.util.AbstractMap#hashCode()}.
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  }