001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: /**
019: * @author Serguei S.Zapreyev
020: * @version $Revision$
021: */package java.lang.reflect;
022:
023: import junit.framework.TestCase;
024:
025: /*
026: * Created on 01.28.2006
027: */
028:
029: @SuppressWarnings(value={"all"})
030: public class AccessibleObjectTest extends TestCase {
031:
032: /**
033: *
034: */
035: public void test_isAccessible_V() {
036: class X {
037: private int fld;
038:
039: private X() {
040: return;
041: }
042: }
043: try {
044: Field f1 = X.class.getDeclaredField("fld");
045: Constructor m1 = X.class
046: .getDeclaredConstructor(new Class[] { java.lang.reflect.AccessibleObjectTest.class });
047: assertTrue("Error1", !f1.isAccessible());
048: assertTrue("Error2", !m1.isAccessible());
049: } catch (Exception e) {
050: fail("Error3: " + e.toString());
051: }
052: }
053:
054: /**
055: *
056: */
057: public void test_setAccessible_Acc_B() {
058: class X {
059: private int fld;
060:
061: private X() {
062: return;
063: }
064: }
065: try {
066: Field f1 = X.class.getDeclaredField("fld");
067: Constructor m1 = X.class
068: .getDeclaredConstructor(new Class[] { java.lang.reflect.AccessibleObjectTest.class });
069: assertTrue("Error1", !f1.isAccessible()
070: && !m1.isAccessible());
071: AccessibleObject[] aa = new AccessibleObject[] { f1, m1 };
072: AccessibleObject.setAccessible(aa, true);
073: assertTrue("Error2", f1.isAccessible() && m1.isAccessible());
074: } catch (Exception e) {
075: fail("Error3: " + e.toString());
076: }
077: }
078:
079: /**
080: *
081: */
082: public void test_setAccessible_B() {
083: class X {
084: private int fld;
085:
086: private X() {
087: return;
088: }
089: }
090: try {
091: Field f1 = X.class.getDeclaredField("fld");
092: f1.setAccessible(true);
093: Constructor m1 = X.class
094: .getDeclaredConstructor(new Class[] { java.lang.reflect.AccessibleObjectTest.class });
095: m1.setAccessible(true);
096: assertTrue("Error1", f1.isAccessible());
097: assertTrue("Error2", m1.isAccessible());
098: } catch (Exception e) {
099: fail("Error3: " + e.toString());
100: }
101: }
102: }
|