1   package org.apache.velocity.test.issues;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.    
20   */
21  
22  import java.util.Collection;
23  import java.util.HashMap;
24  import java.util.Map;
25  import java.util.Set;
26  import org.apache.velocity.test.BaseTestCase;
27  import org.apache.velocity.VelocityContext;
28  
29  /**
30   * This class tests VELOCITY-730.
31   */
32  public class Velocity730TestCase extends BaseTestCase
33  {
34      public Velocity730TestCase(String name)
35      {
36          super(name);
37          //DEBUG = true;
38      }
39  
40      public void setUpContext(VelocityContext ctx)
41      {
42          ctx.put("foo", new Foo());
43      }
44  
45      public void testIt()
46      {
47          String template = "$foo.foo #set( $foo.bar = 'foo' ) $foo.bar";
48          assertEvalEquals("bar foo", template);
49      }
50  
51      public static interface MyMap extends Map
52      {
53      }
54  
55      public abstract static class MyMapImpl
56      {
57          private HashMap map = new HashMap();
58  
59          protected Map map()
60          {
61              return map;
62          }
63  
64          public void clear() 
65          {
66              map.clear();
67          }
68  
69          public boolean containsKey(Object key) 
70          {
71              return map.containsKey(key);
72          }
73  
74          public boolean containsValue(Object value) 
75          {
76              return map.containsValue(value);
77          }
78  
79          public boolean isEmpty() 
80          {
81              return map.isEmpty();
82          }
83  
84          public Set keySet() 
85          {
86              return map.keySet();
87          }
88  
89          public void putAll(Map t) 
90          {
91              map.putAll(t);
92          }
93  
94          public Object remove(Object key) 
95          {
96              return map.remove(key);
97          }
98  
99          public int size() 
100         {
101             return map.size();
102         }
103 
104         public Collection values() 
105         {
106             return map.values();
107         }
108 
109         public Set entrySet()
110         {
111             return map.entrySet();
112         }
113     }
114 
115     private final static class Foo extends MyMapImpl implements MyMap
116     {
117         public Foo()
118         {
119             super();
120             put("foo","bar");
121         }
122 
123         public Object get(Object key) 
124         {
125             return map().get(key);
126         }
127 
128         public Object put(Object k, Object v)
129         {
130             return map().put(k, v);
131         }
132     }
133 
134 }