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