1 /*
   2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /**
  25  * @test 
  26  * @bug 8013497
  27  * @summary test for API: Package.getDeclaredAnnotation()
  28  * @author Charlie Wang
  29  * @library ../../../
  30  * @build AnnotationTest TestCaseGenerator DeclarationGenerator Helper pkg.PkgAnno1 pkg.PkgAnno2 pkg.PkgAnno3 pkg.package-info
  31  * @run main PackageGetDeclaredAnnotationTest
  32  */
  33 import java.lang.annotation.Annotation;
  34 import pkg.PkgAnno1;
  35 import pkg.PkgAnno2;
  36 import pkg.PkgAnno3;
  37 
  38 /*
  39  * This file is intended to test API: Package.getDeclaredAnnotation(). 
  40  * It can be run directly by java command or by jtreg.
  41  * Annotation declarations for the test are defined in pkg.*.
  42  */
  43 public class PackageGetDeclaredAnnotationTest extends AnnotationTest {
  44 
  45     public boolean checkResult() throws Exception {
  46         Package pkg = PkgAnno1.class.getPackage();
  47         Annotation anno = pkg.getDeclaredAnnotation(PkgAnno2.class);
  48         if (!"@PkgAnno2(\"PkgAnno2\") ".equals(Helper.getAnno(anno))) {
  49             return false;
  50         }
  51         anno = pkg.getDeclaredAnnotation(PkgAnno3.class);
  52         if (!"".equals(Helper.getAnno(anno))) {
  53             return false;
  54         }
  55         return true;
  56     }
  57 
  58     public static void main(String[] args) throws Exception {
  59         new PackageGetDeclaredAnnotationTest().test();
  60     }
  61 
  62     @Override
  63     protected String genTestCode(Class<? extends TestCaseGenerator> tcg) {
  64         throw new UnsupportedOperationException("Not supported yet.");
  65     }
  66 }