01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17:
18: /**
19: * @author Evgueni V. Brevnov
20: * @version $Revision$
21: */package java.lang.reflect;
22:
23: import junit.framework.TestCase;
24: import org.apache.harmony.lang.ProtectedMethod;
25: import org.apache.harmony.lang.ProtectedSuccessor;
26:
27: public class ProtectedAccessCheck2 extends TestCase {
28:
29: public void test1() {
30: B2.Inner2 inn2 = new B2.Inner2();
31: new A2().new Inner1().invoke(inn2);
32: }
33: }
34:
35: class A2 extends ProtectedSuccessor {
36:
37: class Inner1 extends ProtectedSuccessor {
38: public void invoke(Object o) {
39: try {
40: assertEquals(0, status);
41: Method m = ProtectedMethod.class.getDeclaredMethod(
42: "protectedMethod", new Class[] {});
43: m.invoke(o, (Object[]) null);
44: } catch (Exception e) {
45: return;
46: }
47: throw new RuntimeException(
48: "IllegalAccessException expected");
49: }
50: }
51:
52: private void assertEquals(int i1, int i2) {
53: if (i1 != i2)
54: throw new RuntimeException("Assertion failed: " + i1
55: + " is not equal to " + i2);
56: }
57: }
58:
59: class B2 extends A2 {
60: static class Inner2 {
61: }
62: }
|