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: package java.lang;
019:
020: import java.lang.annotation.Annotation;
021: import java.lang.pkg3.Pkg3Antn;
022: import java.lang.pkg3.pkg31.Pkg31Antn;
023: import java.lang.reflect.AnnotatedElement;
024:
025: import org.apache.harmony.lang.AnnotatedElementTestFrame;
026:
027: /**
028: * @author Alexey V. Varlamov
029: * @version $Revision$
030: */
031: public class Package5Test extends AnnotatedElementTestFrame {
032:
033: public static void main(String[] args) {
034: junit.textui.TestRunner.run(Package5Test.class);
035: }
036:
037: static {
038: try {
039: Class.forName("java.lang.pkg1.Bogus");
040: } catch (Exception e) {
041: throw new RuntimeException(e);
042: }
043: try {
044: Class.forName("java.lang.pkg2.Bogus");
045: } catch (Exception e) {
046: throw new RuntimeException(e);
047: }
048: try {
049: Class.forName("java.lang.pkg4.Bogus");
050: } catch (Exception e) {
051: throw new RuntimeException(e);
052: }
053: try {
054: Class.forName("java.lang.pkg5.Bogus");
055: } catch (Exception e) {
056: throw new RuntimeException(e);
057: }
058: try {
059: Class.forName("java.lang.pkg6.Bogus");
060: } catch (Exception e) {
061: throw new RuntimeException(e);
062: }
063: }
064:
065: protected @Override
066: AnnotatedElement getElement1() throws Throwable {
067: Package p = Package.getPackage("java.lang.pkg1");
068: assertNotNull("failed to get annotated pkg1", p);
069: return p;
070: }
071:
072: protected @Override
073: AnnotatedElement getElement2() throws Throwable {
074: Package p = Package.getPackage("java.lang.pkg2");
075: assertNotNull("failed to get annotated pkg2", p);
076: return p;
077: }
078:
079: protected @Override
080: AnnotatedElement getElement3() throws Throwable {
081: Package p = Package.getPackage("java.lang");
082: assertNotNull("failed to get package", p);
083: return p;
084: }
085:
086: protected @Override
087: AnnotatedElement getElement4() throws Throwable {
088: Package p = Package.getPackage("java.lang.pkg4");
089: assertNotNull("failed to get annotated pkg5", p);
090: return p;
091: }
092:
093: protected @Override
094: AnnotatedElement getElement5() throws Throwable {
095: Package p = Package.getPackage("java.lang.pkg5");
096: assertNotNull("failed to get annotated pkg5", p);
097: return p;
098: }
099:
100: protected @Override
101: AnnotatedElement getElement6() throws Throwable {
102: Package p = Package.getPackage("java.lang.pkg6");
103: assertNotNull("failed to get annotated pkg6", p);
104: return p;
105: }
106:
107: /**
108: * Package should not be awared of annotations of nested
109: * or "super" packages.
110: */
111: public void testNoInheritance() throws Throwable {
112: Class.forName("java.lang.pkg3.Bogus");
113: Class.forName("java.lang.pkg3.pkg31.Bogus");
114: Package pkg3 = Package.getPackage("java.lang.pkg3");
115: assertNotNull("pkg3", pkg3);
116: Annotation[] an = pkg3.getAnnotations();
117: assertNotNull("all in pkg3", an);
118: assertEquals("number of Annotations in pkg3", 1, an.length);
119: assertNotNull("annotation of pkg3", pkg3
120: .getAnnotation(Pkg3Antn.class));
121:
122: Package pkg31 = Package.getPackage("java.lang.pkg3.pkg31");
123: assertNotNull("pkg31", pkg31);
124: Annotation[] an2 = pkg31.getAnnotations();
125: assertNotNull("all in pkg31", an2);
126: assertEquals("number of Annotations in pkg31", 1, an2.length);
127: assertTrue("annotation of pkg31", pkg31
128: .isAnnotationPresent(Pkg31Antn.class));
129: }
130: }
|