1 package org.apache.velocity.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.velocity.VelocityContext;
23
24
25
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