1   package org.apache.velocity.test;
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 org.apache.velocity.VelocityContext;
23  
24  /**
25   * Used to check that vararg method calls on references work properly
26   */
27  public class PropertyMethodPrecedenceTestCase extends BaseEvalTestCase
28  {
29      public PropertyMethodPrecedenceTestCase(final String name)
30      {
31          super(name);
32      }
33  
34      protected void setContext(VelocityContext context)
35      {
36          context.put("geta", new getGetgetisTool());
37          context.put("getA", new GetgetisTool());
38          context.put("geta2", new get2getisTool());
39          context.put("get_a", new getisTool());
40          context.put("isA", new isTool());
41      }
42  
43      public void testLowercasePropertyMethods()
44      {
45          assertEvalEquals("getfoo", "$geta.foo");
46          assertEvalEquals("getFoo", "$getA.foo");
47          assertEvalEquals("get(foo)", "$get_a.foo");
48          assertEvalEquals("true", "$isA.foo");
49      }
50  
51      public void testUppercasePropertyMethods()
52      {
53          assertEvalEquals("getFoo", "$geta.Foo");
54          assertEvalEquals("getfoo", "$geta2.Foo");
55          assertEvalEquals("getFoo", "$getA.Foo");
56          assertEvalEquals("get(Foo)", "$get_a.Foo");
57          assertEvalEquals("true", "$isA.Foo");
58      }
59  
60  
61      public static class isTool
62      {
63          public boolean isFoo()
64          {
65              return true;
66          }
67      }
68  
69      public static class getisTool extends isTool
70      {
71          public String get(String s)
72          {
73              return "get("+s+")";
74          }
75      }
76  
77      public static class GetgetisTool extends getisTool
78      {
79          public String getFoo()
80          {
81              return "getFoo";
82          }
83      }
84  
85      public static class getGetgetisTool extends GetgetisTool
86      {
87          public String getfoo()
88          {
89              return "getfoo";
90          }
91      }
92  
93      public static class get2getisTool extends getisTool
94      {
95          public String getfoo()
96          {
97              return "getfoo";
98          }
99      }
100 
101 }
102 
103