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 BaseTestCase
28 {
29 public PropertyMethodPrecedenceTestCase(final String name)
30 {
31 super(name);
32
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