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 org.apache.velocity.test.BaseTestCase;
23
24 /**
25 * This class tests VELOCITY-579 and with some related stuff
26 * from VELOCITY-70 thrown in.
27 */
28 public class Velocity579TestCase extends BaseTestCase
29 {
30 public Velocity579TestCase(String name)
31 {
32 super(name);
33 }
34
35 public void testPublicMethodInPrivateImplOfPublicInterface()
36 {
37 context.put("foo", new Foobar());
38 assertEvalEquals("bar", "$foo.foo('bar')");
39 assertEvalEquals("$foo.bar()", "$foo.bar()");
40 }
41
42 public void testPublicMethodInheritedFromPrivateClass() throws Exception
43 {
44 context.put("bar", new MyBar());
45 // ugly hack to avoid failed test when running JDK 1.5 or earlier
46 String javaVersion = System.getProperty("java.version");
47 if (javaVersion.startsWith("1.6"))
48 assertEvalEquals("bar", "$bar.bar()");
49 }
50
51 public static interface Foo
52 {
53 String foo(String s);
54 }
55
56 private static abstract class FooImpl implements Foo
57 {
58 public String foo(String s)
59 {
60 return s == null ? "foo" : s;
61 }
62 }
63
64 private static class Foobar extends FooImpl
65 {
66 public String bar()
67 {
68 return "bar";
69 }
70 }
71
72 public static class MyBar extends Foobar
73 {
74 public String bar()
75 {
76 return super.bar();
77 }
78 }
79
80 }