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.BaseEvalTestCase;
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 BaseEvalTestCase
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 try
47 {
48 Class.forName("java.util.Deque");
49 assertEvalEquals("bar", "$bar.bar()");
50 }
51 catch (ClassNotFoundException cnfe)
52 {
53 //ignore this test in jdk 1.5-
54 System.out.println("Skipping testPublicMethodInheritedFromPrivateClass for pre-1.6 JDK");
55 }
56 }
57
58 public static interface Foo
59 {
60 String foo(String s);
61 }
62
63 private static abstract class FooImpl implements Foo
64 {
65 public String foo(String s)
66 {
67 return s == null ? "foo" : s;
68 }
69 }
70
71 private static class Foobar extends FooImpl
72 {
73 public String bar()
74 {
75 return "bar";
76 }
77 }
78
79 public static class MyBar extends Foobar
80 {
81 }
82
83 }