test/tools/javac/annotations/repeatingAnnotations/combo/ReflectionTest.java

Mon, 18 Feb 2013 14:29:40 -0800

author
jjg
date
Mon, 18 Feb 2013 14:29:40 -0800
changeset 1589
87884cd0fea3
parent 1576
63872da94576
child 2138
4d8af6fda907
permissions
-rw-r--r--

8008339: Test TargetAnnoCombo.java is broken
Reviewed-by: jjh

     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  */
    24 /**
    25  * @test
    26  * @bug      8001457
    27  * @author   sogoel
    28  * @summary  Reflection api tests
    29  * @build    Helper
    30  * @compile  expectedFiles/ExpectedBase.java expectedFiles/ExpectedContainer.java
    31  * @run main ReflectionTest
    32  */
    33 import java.io.File;
    34 import java.io.IOException;
    35 import java.lang.annotation.Annotation;
    36 import java.net.MalformedURLException;
    37 import java.net.URL;
    38 import java.net.URLClassLoader;
    39 import java.util.ArrayList;
    40 import java.util.Arrays;
    41 import java.util.List;
    43 import javax.tools.DiagnosticCollector;
    44 import javax.tools.JavaFileObject;
    46 import expectedFiles.ExpectedBase;
    47 import expectedFiles.ExpectedContainer;
    49 /*
    50  * Objective:
    51  * Test the following 6 methods from java.lang.reflect.AnnotatedElement:
    52  * - getAnnotation(Class<T>)
    53  * - getAnnotations()
    54  * - getDeclaredAnnotations()
    55  * - getDeclaredAnnotation(Class<T>)  // new method in JDK8
    56  * - getAnnotationsByType(Class<T>)         // new method in JDK8
    57  * - getDeclaredAnnotationsByType(Class<T>) // new method in JDK8
    58  * for multiple test cases, for example, BasicNonRepeatable case, BasicRepeatable case
    59  * for each of the src types - class, method, field, package
    60  *
    61  * This test uses following three enums:
    62  * 1. TestCase - Defines the ExpectedBase/ExpectedContainer values for each testCase
    63  *             - getTestFiles() - Creates list of JavaFileObjects for the primary
    64  *                                src types (class, method, field, package)
    65  *             - Each testCase is a new scenario with a combination of @Repeatable
    66  *               relationship present/absent in conjunction with @Inherited.
    67  *               For eg: BasicNonRepeatable_Legacy - It is a pre-JDK8 way of writing a single
    68  *                       annotation on a given srcType( class, method, field, package)
    69  *                       BasicRepeatable - It is a JDK8 way of writing repeating annotations
    70  *                       on a given srcType with a @Repeatable relationship
    71  *                       defined between Foo and FooContainer.
    72  *
    73  * 2. SrcType - Defines templates used in creation of test src
    74  *            - Defines getExpectedBase() and getExpectedContainer() for primary src types
    75  * 3. TestMethod - Defines getActualAnnoBase(), getActualAnnoContainer(), getExpectedAnnoBase(),
    76  *                 and getExpectedAnnoContainer() for each of the 6 methods that are being tested
    77  *                 in java.lang.reflect.AnnotatedElement
    78  *
    79  * Test execution flow:
    80  * - Loop over each of the src types and each test cases
    81  * - Creates test src for each flow, compile it, load the class object
    82  * - Run all 6 methods on this class object
    83  * - Get expected and actual annotations for each object and compare them.
    84  * - Increment the error counter if the annotations don't match.
    85  *
    86  * The test fails if the number of errors is greater than 0.
    87  */
    88 public class ReflectionTest {
    90     static int errors = 0;
    91     // Variables used in creating test src for a given testcase/testSrcType
    92     static final String TESTPKG = "testpkg";
    93     static final String TESTMETHOD = "testMethod";
    94     static final String TESTFIELD = "testField";
    95     static final String PKGINFONAME = TESTPKG + ".package-info";
    96     static final String SUPERCLASS = "SuperClass";
    97     static final String TESTINTERFACE = "TestInterface";
    98     /*
    99      *  Set it to true to get more debug information
   100      */
   101     static final boolean DEBUG = false;
   103     public static void main(String args[]) throws Exception {
   104         ReflectionTest test = new ReflectionTest();
   105         test.runTest();
   106     }
   108     public void runTest() throws Exception {
   110         ClassLoader parentClassLoader = getLoader();
   111         String className = "";
   112         Iterable<? extends JavaFileObject> files = null;
   114         for (SrcType srcType : SrcType.getSrcTypes()) {
   115             for (TestCase testCase : TestCase.values()) {
   116                 className = testCase + "_" + srcType;
   117                 debugPrint("*****************************************");
   118                 System.out.println("Running Test for ClassName: " + className);
   120                 // @Inherited only applicable for class, exclude cases for
   121                 // package, method, field
   122                 if (testCase.name().contains("Inherited")
   123                         && (srcType != SrcType.CLASS)) {
   124                     continue;
   125                 }
   127                 // Get list of JavaFileObjects to be compiled
   128                 files = testCase.getTestFiles(srcType, className);
   129                 if (srcType == SrcType.PACKAGE) {
   130                     className = TESTPKG + "." + className;
   131                 }
   132                 DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
   134                 // Compile the list of JavaFileObjects
   135                 try {
   136                     Helper.compileCode(diagnostics, files);
   137                 } catch (Exception ex) {
   138                     printTestSrc(files);
   139                     throw new RuntimeException(
   140                             "Exception when compiling class " + className, ex);
   141                 }
   143                 // Get Class object for the compiled class
   144                 Class<?> c = loadClass(className, parentClassLoader, Helper.destDir);
   145                 if (c != null) {
   146                     // For the loaded class object, compare expected and actual annotation values
   147                     // for each of the methods under test from java.lang.reflect.AnnotatedElement
   148                     checkAnnoValues(srcType, c);
   149                 } else {
   150                     error("Could not load className = " + c);
   151                 }
   152             }
   153         }
   155         if (getNumErrors() > 0) {
   156             System.err.println("Test failed with " + getNumErrors() + " errors");
   157             throw new RuntimeException();
   158         }
   159     }
   161     /*
   162      *  Each test case in this enum has the following:
   163      *  - Define each test case with its @ExpectedBase and @ExpectedContainer annotations
   164      *  - Override getTestFiles() that creates list of JavaFileObjects for each case
   165      *    based on the src type.
   166      */
   167     enum TestCase {
   168         BasicNonRepeatable_Legacy(
   169         "@ExpectedBase(value=Foo.class, "
   170                 + "getAnnotationVal = \"Foo\", "
   171                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
   172                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
   173                 + "getDeclAnnoVal = \"Foo\", "
   174                 + "getAnnosArgs = {\"Foo\"}, "
   175                 + "getDeclAnnosArgs = {\"Foo\"}) ",
   176         "@ExpectedContainer") {
   178             @Override
   179             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   180                     String className) {
   181                 String anno = "";
   182                 String replaceVal = "";
   183                 String testSrc = "";
   184                 String pkgInfoContents = "";
   185                 String contents = "";
   187                 JavaFileObject pkgFileObj = null;
   188                 JavaFileObject srcFileObj = null;
   189                 Iterable<? extends JavaFileObject> files = null;
   191                 String expectedVals = "\n" + getExpectedBase() + "\n"
   192                         + getExpectedContainer() + "\n";
   193                 StringBuilder commonStmts = new StringBuilder();
   194                 anno = Helper.ContentVars.BASEANNO.getVal();
   195                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
   196                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
   197                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
   198                         .append(Helper.ContentVars.BASE.getVal());
   199                 switch (srcType) {
   200                     case PACKAGE:
   201                         /*
   202                         Sample package-info.java
   203                         @ExpectedBase
   204                         @ExpectedContainer
   205                         @Foo
   206                         package testpkg;
   208                         @Retention(RetentionPolicy.RUNTIME)
   209                         @interface Foo {}
   211                         Sample testSrc:
   212                         package testpkg;
   213                         class A {}
   214                          */
   215                         testSrc = srcType.getTemplate().replace("#CN", className);
   216                         contents = testSrc;
   217                         srcFileObj = Helper.getFile(className, contents);
   219                         replaceVal = expectedVals + "\n" + anno;
   220                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
   221                                 .replace("#REPLACE1", replaceVal)
   222                                 .replace("#REPLACE2", commonStmts);
   223                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
   225                         files = Arrays.asList(pkgFileObj, srcFileObj);
   226                         break;
   227                     default:
   228                         // class, method, field
   229                     /*
   230                         Sample testSrc for class
   231                         @Retention(RetentionPolicy.RUNTIME)
   232                         @interface Foo {}
   234                         @ExpectedBase
   235                         @ExpectedContainer
   236                         @Foo
   237                         class A {}
   238                          */
   239                         replaceVal = expectedVals + anno;
   240                         testSrc = srcType.getTemplate().replace("#CN", className)
   241                                 .replace("#REPLACE", replaceVal);
   242                         contents = commonStmts + testSrc;
   243                         srcFileObj = Helper.getFile(className, contents);
   244                         files = Arrays.asList(srcFileObj);
   245                 }
   246                 return files;
   247             }
   248         },
   249         SingleAnnoInherited_Legacy(
   250         "@ExpectedBase(value=Foo.class, "
   251                 + "getAnnotationVal = \"Foo\", "
   252                 + "getAnnotationsVals = {\"Foo\", \"ExpectedBase\", \"ExpectedContainer\"}, "
   253                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
   254                 + "getDeclAnnoVal = \"NULL\", "
   255                 + "getAnnosArgs = {\"Foo\"}, "
   256                 + "getDeclAnnosArgs = {})",
   257         "@ExpectedContainer") {
   259             @Override
   260             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   261                     String className) {
   262                 String anno = "";
   263                 String replaceVal = "";
   264                 String contents = "";
   265                 JavaFileObject srcFileObj = null;
   266                 Iterable<? extends JavaFileObject> files = null;
   268                 String expectedVals = "\n" + getExpectedBase() + "\n"
   269                         + getExpectedContainer() + "\n";
   270                 StringBuilder commonStmts = new StringBuilder();
   272                 /*
   273                 Sample testSrc:
   274                 @Retention(RetentionPolicy.RUNTIME)
   275                 @Inherited
   276                 @interface Foo {}
   278                 @Foo
   279                 class SuperClass { }
   281                 @ExpectedBase
   282                 @ExpectedContainer
   283                 class SubClass extends SuperClass {}
   284                  */
   286                 // @Inherited only works for classes, no switch cases for
   287                 // method, field, package
   288                 anno = Helper.ContentVars.BASEANNO.getVal();
   289                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
   290                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
   291                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
   292                         .append(Helper.ContentVars.INHERITED.getVal())
   293                         .append(Helper.ContentVars.BASE.getVal());
   295                 if (srcType == SrcType.CLASS) {
   296                     // Contents for SuperClass
   297                     replaceVal = commonStmts + "\n" + anno;
   298                     String superClassContents = srcType.getTemplate()
   299                             .replace("#CN", SUPERCLASS).replace("#REPLACE", replaceVal);
   301                     // Contents for SubClass that extends SuperClass
   302                     replaceVal = expectedVals;
   303                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
   304                             .replace("#CN", className).replace("#SN", SUPERCLASS)
   305                             .replace("#REPLACE", replaceVal);
   307                     contents = superClassContents + subClassContents;
   308                     srcFileObj = Helper.getFile(className, contents);
   309                     files = Arrays.asList(srcFileObj);
   310                 }
   311                 return files;
   312             }
   313         },
   314         InheritedAnnoOnInterface_Legacy(
   315         "@ExpectedBase(value=Foo.class, "
   316                 + "getAnnotationVal = \"NULL\", "
   317                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
   318                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"},"
   319                 + "getDeclAnnoVal = \"NULL\"," + "getAnnosArgs = {},"
   320                 + "getDeclAnnosArgs = {})",
   321         "@ExpectedContainer") {
   323             @Override
   324             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   325                     String className) {
   326                 String anno = "";
   327                 String replaceVal = "";
   328                 String contents = "";
   329                 JavaFileObject srcFileObj = null;
   330                 Iterable<? extends JavaFileObject> files = null;
   332                 String expectedVals = "\n" + getExpectedBase() + "\n"
   333                         + getExpectedContainer() + "\n";
   334                 StringBuilder commonStmts = new StringBuilder();
   336                 /*
   337                 Sample test src:
   338                 @Retention(RetentionPolicy.RUNTIME)
   339                 @Inherited
   340                 @interface Foo {}
   342                 @Foo
   343                 interface TestInterface { }
   345                 @ExpectedBase
   346                 @ExpectedContainer
   347                 class A implements TestInterface {}
   348                  */
   349                 anno = Helper.ContentVars.BASEANNO.getVal();
   350                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
   351                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
   352                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
   353                         .append(Helper.ContentVars.INHERITED.getVal())
   354                         .append(Helper.ContentVars.BASE.getVal());
   356                 if (srcType == SrcType.CLASS) {
   357                     // Contents for TestInterface
   358                     replaceVal = commonStmts + "\n" + anno;
   359                     String interfaceContents = SrcType.INTERFACE.getTemplate()
   360                             .replace("#IN", TESTINTERFACE)
   361                             .replace("#REPLACE", replaceVal);
   363                     // Contents for class implementing TestInterface
   364                     replaceVal = expectedVals;
   365                     String classContents = SrcType.INTERFACEIMPL.getTemplate()
   366                             .replace("#CN", className).replace("#IN", TESTINTERFACE)
   367                             .replace("#REPLACE", replaceVal);
   369                     contents = interfaceContents + classContents;
   370                     srcFileObj = Helper.getFile(className, contents);
   371                     files = Arrays.asList(srcFileObj);
   372                 }
   373                 return files;
   374             }
   375         },
   376         AnnoOnSuperAndSubClass_Inherited_Legacy(
   377         "@ExpectedBase(value=Foo.class, "
   378                 + "getAnnotationVal = \"Foo\", "
   379                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
   380                 + // override every annotation on superClass
   381                 "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
   382                 + // ignores inherited annotations
   383                 "getDeclAnnoVal = \"Foo\", " // ignores inherited
   384                 + "getAnnosArgs = {\"Foo\"}, "
   385                 + "getDeclAnnosArgs = { \"Foo\" })", // ignores inherited
   386         "@ExpectedContainer(value=FooContainer.class, "
   387                 + "getAnnotationVal = \"NULL\", "
   388                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
   389                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
   390                 + // ignores inherited annotations
   391                 "getDeclAnnoVal = \"NULL\", " + // ignores inherited
   392                 "getAnnosArgs = {}, " + "getDeclAnnosArgs = {})") { // ignores inherited
   394             @Override
   395             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   396                     String className) {
   397                 String anno = "";
   398                 String replaceVal = "";
   399                 String contents = "";
   400                 JavaFileObject srcFileObj = null;
   401                 Iterable<? extends JavaFileObject> files = null;
   403                 String expectedVals = "\n" + getExpectedBase() + "\n"
   404                         + getExpectedContainer() + "\n";
   405                 StringBuilder commonStmts = new StringBuilder();
   407                 /*
   408                 Sample test src
   409                 @Retention(RetentionPolicy.RUNTIME)
   410                 @Inherited
   411                 @interface Foo {}
   413                 @Inherited
   414                 @interface FooContainer {
   415                 Foo[] value();
   416                 }
   418                 @Foo
   419                 class SuperClass { }
   421                 @ExpectedBase
   422                 @ExpectedContainer
   423                 @Foo
   424                 class SubClass extends SuperClass {}
   425                  */
   426                 // @Inherited only works for classes, no switch cases for
   427                 // method, field, package
   428                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
   429                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
   430                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
   431                         .append(Helper.ContentVars.INHERITED.getVal())
   432                         .append(Helper.ContentVars.BASE.getVal())
   433                         .append(Helper.ContentVars.INHERITED.getVal())
   434                         .append(Helper.ContentVars.CONTAINER.getVal());
   436                 if (srcType == SrcType.CLASS) {
   437                     // Contents for SuperClass
   438                     anno = Helper.ContentVars.BASEANNO.getVal();
   439                     replaceVal = commonStmts + "\n" + anno;
   440                     String superClassContents = srcType.getTemplate()
   441                             .replace("#CN", SUPERCLASS).replace("#REPLACE", replaceVal);
   443                     // Contents for SubClass that extends SuperClass
   444                     replaceVal = expectedVals + "\n" + anno;
   445                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
   446                             .replace("#CN", className).replace("#SN", SUPERCLASS)
   447                             .replace("#REPLACE", replaceVal);
   449                     contents = superClassContents + subClassContents;
   450                     srcFileObj = Helper.getFile(className, contents);
   451                     files = Arrays.asList(srcFileObj);
   452                 }
   453                 return files;
   454             }
   455         },
   456         BasicContainer_Legacy(
   457         "@ExpectedBase(value = Foo.class, "
   458                 + "getAnnotationVal = \"NULL\","
   459                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
   460                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
   461                 + "getDeclAnnoVal = \"NULL\", " + "getAnnosArgs = {}, "
   462                 + "getDeclAnnosArgs = {} )",
   463         "@ExpectedContainer(value=FooContainer.class, "
   464                 + "getAnnotationVal = \"FooContainer\", "
   465                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
   466                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
   467                 + "getDeclAnnoVal = \"FooContainer\", "
   468                 + "getAnnosArgs = {\"FooContainer\"}, "
   469                 + "getDeclAnnosArgs = {\"FooContainer\"} )") {
   471             @Override
   472             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   473                     String className) {
   474                 String anno = "";
   475                 String replaceVal = "";
   476                 String testSrc = "";
   477                 String pkgInfoContents = "";
   478                 String contents = "";
   480                 JavaFileObject pkgFileObj = null;
   481                 JavaFileObject srcFileObj = null;
   482                 Iterable<? extends JavaFileObject> files = null;
   484                 String expectedVals = "\n" + getExpectedBase() + "\n"
   485                         + getExpectedContainer() + "\n";
   486                 StringBuilder commonStmts = new StringBuilder();
   488                 anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
   489                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
   490                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
   491                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
   492                         .append(Helper.ContentVars.BASE.getVal())
   493                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
   494                         .append(Helper.ContentVars.CONTAINER.getVal());
   495                 switch (srcType) {
   496                     case PACKAGE:
   497                         /*
   498                         Sample package-info.java
   499                         @ExpectedBase
   500                         @ExpectedContainer
   501                         @FooContainer(value = {@Foo, @Foo})
   502                         package testpkg;
   504                         @Retention(RetentionPolicy.RUNTIME)
   505                         @interface Foo {}
   507                         @Retention(RetentionPolicy.RUNTIME)
   508                         @interface FooContainer {
   509                         Foo[] value();
   510                         }
   512                         Sample testSrc:
   513                         package testpkg;
   514                         class A {}
   515                          */
   516                         testSrc = srcType.getTemplate().replace("#CN", className);
   517                         contents = testSrc;
   518                         srcFileObj = Helper.getFile(className, contents);
   520                         replaceVal = "\n" + expectedVals + "\n" + anno;
   521                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
   522                                 .replace("#REPLACE1", replaceVal)
   523                                 .replace("#REPLACE2", commonStmts);
   524                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
   525                         files = Arrays.asList(pkgFileObj, srcFileObj);
   526                         break;
   527                     default:
   528                         /*
   529                         Sample testSrc for class:
   530                         @Retention(RetentionPolicy.RUNTIME)
   531                         @Inherited
   532                         @interface Foo {}
   534                         @Retention(RetentionPolicy.RUNTIME)
   535                         @Inherited
   536                         @interface FooContainer {
   537                         Foo[] value();
   538                         }
   540                         @ExpectedBase
   541                         @ExpectedContainer
   542                         @FooContainer(value = {@Foo, @Foo})
   543                         class A {}
   544                          */
   545                         replaceVal = expectedVals + anno;
   546                         testSrc = srcType.getTemplate().replace("#CN", className)
   547                                 .replace("#REPLACE", replaceVal);
   548                         contents = commonStmts + testSrc;
   549                         srcFileObj = Helper.getFile(className, contents);
   550                         files = Arrays.asList(srcFileObj);
   551                 }
   552                 return files;
   553             }
   554         },
   555         SingleAndContainerOnSuper_Legacy(
   556         "@ExpectedBase(value = Foo.class, "
   557                 + "getAnnotationVal = \"Foo\","
   558                 + "getAnnotationsVals = {"
   559                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   560                 + "getDeclAnnosVals = {"
   561                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   562                 + "getDeclAnnoVal = \"Foo\", "
   563                 + "getAnnosArgs = {\"Foo\"}, "
   564                 + "getDeclAnnosArgs = {\"Foo\"} )",
   565         "@ExpectedContainer(value=FooContainer.class, "
   566                 + "getAnnotationVal = \"FooContainer\", "
   567                 + "getAnnotationsVals = {"
   568                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   569                 + "getDeclAnnosVals = {"
   570                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   571                 + "getDeclAnnoVal = \"FooContainer\", "
   572                 + "getAnnosArgs = {\"FooContainer\"}, "
   573                 + "getDeclAnnosArgs = {\"FooContainer\"} )") {
   575             @Override
   576             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   577                     String className) {
   578                 String anno = "";
   579                 String replaceVal = "";
   580                 String testSrc = "";
   581                 String pkgInfoContents = "";
   582                 String contents = "";
   584                 JavaFileObject pkgFileObj = null;
   585                 JavaFileObject srcFileObj = null;
   586                 Iterable<? extends JavaFileObject> files = null;
   588                 String expectedVals = "\n" + getExpectedBase() + "\n"
   589                         + getExpectedContainer() + "\n";
   590                 StringBuilder commonStmts = new StringBuilder();
   592                 anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
   593                         + Helper.ContentVars.BASEANNO.getVal();
   594                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
   595                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
   596                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
   597                         .append(Helper.ContentVars.BASE.getVal())
   598                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
   599                         .append(Helper.ContentVars.CONTAINER.getVal());
   600                 switch (srcType) {
   601                     case PACKAGE:
   602                         /*
   603                         Sample package-info.java
   604                         @ExpectedBase
   605                         @ExpectedContainer
   606                         @Foo
   607                         @FooContainer(value = {@Foo, @Foo})
   608                         package testpkg;
   610                         @Retention(RetentionPolicy.RUNTIME)
   611                         @interface Foo {}
   613                         @Retention(RetentionPolicy.RUNTIME)
   614                         @interface FooContainer {
   615                         Foo[] value();
   616                         }
   618                         Sample testSrc:
   619                         package testpkg;
   620                         class A {}
   621                          */
   622                         testSrc = srcType.getTemplate().replace("#CN", className);
   623                         contents = testSrc;
   625                         srcFileObj = Helper.getFile(className, contents);
   627                         replaceVal = "\n" + expectedVals + "\n" + anno;
   628                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
   629                                 .replace("#REPLACE1", replaceVal)
   630                                 .replace("#REPLACE2", commonStmts);
   631                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
   632                         files = Arrays.asList(pkgFileObj, srcFileObj);
   633                         break;
   634                     default:
   635                         /*
   636                         Sample testSrc for class:
   637                         @Retention(RetentionPolicy.RUNTIME)
   638                         @Inherited
   639                         @interface Foo {}
   641                         @Retention(RetentionPolicy.RUNTIME)
   642                         @Inherited
   643                         @interface FooContainer {
   644                         Foo[] value();
   645                         }
   647                         @ExpectedBase
   648                         @ExpectedContainer
   649                         @Foo
   650                         @FooContainer(value = {@Foo, @Foo})
   651                         class A {}
   652                          */
   653                         replaceVal = expectedVals + anno;
   654                         testSrc = srcType.getTemplate().replace("#CN", className)
   655                                 .replace("#REPLACE", replaceVal);
   656                         contents = commonStmts + testSrc;
   658                         srcFileObj = Helper.getFile(className, contents);
   659                         files = Arrays.asList(srcFileObj);
   660                 }
   661                 return files;
   662             }
   663         },
   664         BasicContainer_Inherited_Legacy(
   665         "@ExpectedBase(value = Foo.class, "
   666                 + "getAnnotationVal = \"NULL\","
   667                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
   668                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
   669                 + "getDeclAnnoVal = \"NULL\", "
   670                 + "getAnnosArgs = {}, "
   671                 + "getDeclAnnosArgs = {} )",
   672         "@ExpectedContainer(value=FooContainer.class, "
   673                 + "getAnnotationVal = \"FooContainer\", "
   674                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
   675                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
   676                 + "getDeclAnnoVal = \"NULL\", "
   677                 + "getAnnosArgs = {\"FooContainer\"}, "
   678                 + "getDeclAnnosArgs = {} )") {
   680             @Override
   681             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   682                     String className) {
   683                 String anno = "";
   684                 String replaceVal = "";
   685                 String contents = "";
   686                 JavaFileObject srcFileObj = null;
   687                 Iterable<? extends JavaFileObject> files = null;
   689                 String expectedVals = "\n" + getExpectedBase() + "\n"
   690                         + getExpectedContainer() + "\n";
   691                 StringBuilder commonStmts = getCommonStmts(false);
   693                 /*
   694                 Sample testSrc:
   695                 @Retention(RetentionPolicy.RUNTIME)
   696                 @Inherited
   697                 @interface Foo {}
   699                 @Retention(RetentionPolicy.RUNTIME)
   700                 @Inherited
   701                 @interface FooContainer {
   702                 Foo[] value();
   703                 }
   705                 @FooContainer(value = {@Foo, @Foo})
   706                 class SuperClass { }
   708                 @ExpectedBase
   709                 @ExpectedContainer
   710                 class SubClass extends SuperClass {}
   711                  */
   712                 // @Inherited only works for classes, no switch cases for
   713                 // method, field, package
   715                 if (srcType == SrcType.CLASS) {
   716                     // Contents for SuperClass
   717                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
   718                     replaceVal = commonStmts + "\n" + anno;
   719                     String superClassContents = srcType.getTemplate()
   720                             .replace("#CN", SUPERCLASS)
   721                             .replace("#REPLACE", replaceVal);
   723                     // Contents for SubClass that extends SuperClass
   724                     replaceVal = expectedVals;
   725                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
   726                             .replace("#CN", className)
   727                             .replace("#SN", SUPERCLASS)
   728                             .replace("#REPLACE", replaceVal);
   730                     contents = superClassContents + subClassContents;
   731                     srcFileObj = Helper.getFile(className, contents);
   732                     files = Arrays.asList(srcFileObj);
   733                 }
   734                 return files;
   735             }
   736         },
   737         ContainerOnSuperSingleOnSub_Inherited_Legacy(
   738         "@ExpectedBase(value=Foo.class, "
   739                 + "getAnnotationVal = \"Foo\", "
   740                 + "getAnnotationsVals = {"
   741                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   742                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"},"
   743                 + "getDeclAnnoVal = \"Foo\","
   744                 + "getAnnosArgs = {\"Foo\"},"
   745                 + "getDeclAnnosArgs = {\"Foo\"})",
   746         "@ExpectedContainer(value=FooContainer.class, "
   747                 + "getAnnotationVal = \"FooContainer\", "
   748                 + "getAnnotationsVals = {"
   749                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   750                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"},"
   751                 + "getDeclAnnoVal = \"NULL\","
   752                 + "getAnnosArgs = {\"FooContainer\"},"
   753                 + "getDeclAnnosArgs = {})") {
   755             @Override
   756             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   757                     String className) {
   758                 String anno = "";
   759                 String replaceVal = "";
   760                 String contents = "";
   761                 JavaFileObject srcFileObj = null;
   762                 Iterable<? extends JavaFileObject> files = null;
   764                 String expectedVals = "\n" + getExpectedBase() + "\n"
   765                         + getExpectedContainer() + "\n";
   766                 StringBuilder commonStmts = getCommonStmts(false);
   768                 /*
   769                 Sample testSrc:
   770                 @Retention(RetentionPolicy.RUNTIME)
   771                 @Inherited
   772                 @interface Foo {}
   774                 @Retention(RetentionPolicy.RUNTIME)
   775                 @Inherited
   776                 @interface FooContainer {
   777                 Foo[] value();
   778                 }
   780                 @FooContainer(value = {@Foo, @Foo})
   781                 class SuperClass { }
   783                 @ExpectedBase
   784                 @ExpectedContainer
   785                 @Foo
   786                 class SubClass extends SuperClass {}
   787                  */
   788                 // @Inherited only works for classes, no switch cases for
   789                 // method, field, package
   791                 if (srcType == SrcType.CLASS) {
   792                     // Contents for SuperClass
   793                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
   794                     replaceVal = commonStmts + "\n" + anno;
   795                     String superClassContents = srcType.getTemplate()
   796                             .replace("#CN", SUPERCLASS)
   797                             .replace("#REPLACE", replaceVal);
   799                     // Contents for SubClass that extends SuperClass
   800                     anno = Helper.ContentVars.BASEANNO.getVal();
   801                     replaceVal = expectedVals + "\n" + anno;
   802                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
   803                             .replace("#CN", className)
   804                             .replace("#SN", SUPERCLASS)
   805                             .replace("#REPLACE", replaceVal);
   807                     contents = superClassContents + subClassContents;
   808                     srcFileObj = Helper.getFile(className, contents);
   809                     files = Arrays.asList(srcFileObj);
   810                 }
   811                 return files;
   812             }
   813         },
   814         ContainerAndSingleOnSuperSingleOnSub_Inherited_Legacy(
   815         "@ExpectedBase(value=Foo.class, "
   816                 + "getAnnotationVal = \"Foo\", "
   817                 + "getAnnotationsVals = {"
   818                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   819                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"},"
   820                 + "getDeclAnnoVal = \"Foo\","
   821                 + "getAnnosArgs = {\"Foo\"},"
   822                 + "getDeclAnnosArgs = {\"Foo\"})",
   823         "@ExpectedContainer(value=FooContainer.class, "
   824                 + "getAnnotationVal = \"FooContainer\", "
   825                 + "getAnnotationsVals = {"
   826                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   827                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"},"
   828                 + "getDeclAnnoVal = \"NULL\","
   829                 + "getAnnosArgs = {\"FooContainer\"},"
   830                 + "getDeclAnnosArgs = {})") {
   832             @Override
   833             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   834                     String className) {
   835                 String anno = "";
   836                 String replaceVal = "";
   837                 String contents = "";
   838                 JavaFileObject srcFileObj = null;
   839                 Iterable<? extends JavaFileObject> files = null;
   841                 String expectedVals = "\n" + getExpectedBase() + "\n"
   842                         + getExpectedContainer() + "\n";
   843                 StringBuilder commonStmts = getCommonStmts(false);
   845                 /*
   846                 Sample testSrc:
   847                 @Retention(RetentionPolicy.RUNTIME)
   848                 @Inherited
   849                 @interface Foo {}
   851                 @Retention(RetentionPolicy.RUNTIME)
   852                 @Inherited
   853                 @interface FooContainer {
   854                 Foo[] value();
   855                 }
   857                 @FooContainer(value = {@Foo, @Foo}) @Foo
   858                 class SuperClass { }
   860                 @ExpectedBase
   861                 @ExpectedContainer
   862                 @Foo
   863                 class SubClass extends SuperClass {}
   864                  */
   865                 // @Inherited only works for classes, no switch cases for
   866                 // method, field, package
   868                 if (srcType == SrcType.CLASS) {
   869                     // Contents for SuperClass
   870                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
   871                             + Helper.ContentVars.BASEANNO.getVal();
   872                     replaceVal = commonStmts + "\n" + anno;
   873                     String superClassContents = srcType.getTemplate()
   874                             .replace("#CN", SUPERCLASS)
   875                             .replace("#REPLACE", replaceVal);
   877                     // Contents for SubClass that extends SuperClass
   878                     anno = Helper.ContentVars.BASEANNO.getVal();
   879                     replaceVal = expectedVals + "\n" + anno;
   880                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
   881                             .replace("#CN", className).replace("#SN", SUPERCLASS)
   882                             .replace("#REPLACE", replaceVal);
   884                     contents = superClassContents + subClassContents;
   885                     srcFileObj = Helper.getFile(className, contents);
   886                     files = Arrays.asList(srcFileObj);
   887                 }
   888                 return files;
   889             }
   890         },
   891         SingleOnSuperContainerOnSub_Inherited_Legacy(
   892         "@ExpectedBase(value=Foo.class, "
   893                 + "getAnnotationVal = \"Foo\", "
   894                 + "getAnnotationsVals = {"
   895                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   896                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"},"
   897                 + "getDeclAnnoVal = \"NULL\","
   898                 + "getAnnosArgs = {\"Foo\"},"
   899                 + "getDeclAnnosArgs = {})",
   900         "@ExpectedContainer(value=FooContainer.class, "
   901                 + "getAnnotationVal = \"FooContainer\", "
   902                 + "getAnnotationsVals = {"
   903                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   904                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"},"
   905                 + "getDeclAnnoVal = \"FooContainer\","
   906                 + "getAnnosArgs = {\"FooContainer\"},"
   907                 + "getDeclAnnosArgs = {\"FooContainer\"})") {
   909             @Override
   910             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   911                     String className) {
   912                 String anno = "";
   913                 String replaceVal = "";
   914                 String contents = "";
   916                 JavaFileObject srcFileObj = null;
   917                 Iterable<? extends JavaFileObject> files = null;
   919                 String expectedVals = "\n" + getExpectedBase() + "\n"
   920                         + getExpectedContainer() + "\n";
   921                 StringBuilder commonStmts = getCommonStmts(false);
   923                 /*
   924                 Sample testSrc:
   925                 @Retention(RetentionPolicy.RUNTIME)
   926                 @Inherited
   927                 @interface Foo {}
   929                 @Retention(RetentionPolicy.RUNTIME)
   930                 @Inherited
   931                 @interface FooContainer {
   932                 Foo[] value();
   933                 }
   935                 @Foo
   936                 class SuperClass { }
   938                 @ExpectedBase
   939                 @ExpectedContainer
   940                 @FooContainer(value = {@Foo, @Foo})
   941                 class SubClass extends SuperClass {}
   942                  */
   944                 if (srcType == SrcType.CLASS) {
   945                     //Contents for SuperClass
   946                     anno = Helper.ContentVars.BASEANNO.getVal();
   947                     replaceVal = commonStmts + "\n" + anno;
   948                     String superClassContents = srcType.getTemplate()
   949                             .replace("#CN", SUPERCLASS)
   950                             .replace("#REPLACE", replaceVal);
   952                     //Contents for SubClass that extends SuperClass
   953                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
   954                     replaceVal = expectedVals + "\n" + anno;
   955                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
   956                             .replace("#CN", className).replace("#SN", SUPERCLASS)
   957                             .replace("#REPLACE", replaceVal);
   959                     contents = superClassContents + subClassContents;
   960                     srcFileObj = Helper.getFile(className, contents);
   961                     files = Arrays.asList(srcFileObj);
   962                 }
   963                 return files;
   964             }
   965         },
   966         SingleOnSuperContainerAndSingleOnSub_Inherited_Legacy(
   967         "@ExpectedBase(value=Foo.class, "
   968                 + "getAnnotationVal = \"Foo\", "
   969                 + "getAnnotationsVals = {"
   970                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   971                 + "getDeclAnnosVals = {"
   972                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"},"
   973                 + "getDeclAnnoVal = \"Foo\","
   974                 + "getAnnosArgs = {\"Foo\"},"
   975                 + "getDeclAnnosArgs = {\"Foo\"})",
   976         "@ExpectedContainer(value=FooContainer.class, "
   977                 + "getAnnotationVal = \"FooContainer\", "
   978                 + "getAnnotationsVals = {"
   979                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
   980                 + "getDeclAnnosVals = {"
   981                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"},"
   982                 + "getDeclAnnoVal = \"FooContainer\","
   983                 + "getAnnosArgs = {\"FooContainer\"},"
   984                 + "getDeclAnnosArgs = {\"FooContainer\"})") {
   986             @Override
   987             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
   988                     String className) {
   989                 String anno = "";
   990                 String replaceVal = "";
   991                 String contents = "";
   993                 JavaFileObject srcFileObj = null;
   994                 Iterable<? extends JavaFileObject> files = null;
   996                 String expectedVals = "\n" + getExpectedBase() + "\n"
   997                         + getExpectedContainer() + "\n";
   998                 StringBuilder commonStmts = getCommonStmts(false);
  1000                 /*
  1001                 Sample testSrc:
  1002                 @Retention(RetentionPolicy.RUNTIME)
  1003                 @Inherited
  1004                 @interface Foo {}
  1006                 @Retention(RetentionPolicy.RUNTIME)
  1007                 @Inherited
  1008                 @interface FooContainer {
  1009                 Foo[] value();
  1012                 @Foo
  1013                 class SuperClass { }
  1015                 @ExpectedBase
  1016                 @ExpectedContainer
  1017                 @FooContainer(value = {@Foo, @Foo}) @Foo
  1018                 class SubClass extends SuperClass {}
  1019                  */
  1021                 if (srcType == SrcType.CLASS) {
  1022                     //Contents for SuperClass
  1023                     anno = Helper.ContentVars.BASEANNO.getVal();
  1024                     replaceVal = commonStmts + "\n" + anno;
  1025                     String superClassContents = srcType.getTemplate()
  1026                             .replace("#CN", SUPERCLASS)
  1027                             .replace("#REPLACE", replaceVal);
  1029                     //Contents for SubClass that extends SuperClass
  1030                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
  1031                             + Helper.ContentVars.BASEANNO.getVal();
  1032                     replaceVal = expectedVals + "\n" + anno;
  1033                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1034                             .replace("#CN", className).replace("#SN", SUPERCLASS)
  1035                             .replace("#REPLACE", replaceVal);
  1037                     contents = superClassContents + subClassContents;
  1038                     srcFileObj = Helper.getFile(className, contents);
  1039                     files = Arrays.asList(srcFileObj);
  1041                 return files;
  1043         },
  1044         BasicRepeatable(
  1045         "@ExpectedBase(value=Foo.class, "
  1046                 + "getAnnotationVal = \"NULL\", "
  1047                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\" }, "
  1048                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"},"
  1049                 + "getDeclAnnoVal = \"NULL\","
  1050                 + "getAnnosArgs = {\"Foo\", \"Foo\"},"
  1051                 + "getDeclAnnosArgs = {\"Foo\", \"Foo\"})",
  1052         "@ExpectedContainer(value=FooContainer.class, "
  1053                 + "getAnnotationVal = \"FooContainer\","
  1054                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"},"
  1055                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1056                 + "getDeclAnnoVal = \"FooContainer\","
  1057                 + "getAnnosArgs = {\"FooContainer\"},"
  1058                 + "getDeclAnnosArgs = {\"FooContainer\"} )") {
  1060             @Override
  1061             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1062                     String className) {
  1063                 String anno = "";
  1064                 String replaceVal = "";
  1065                 String testSrc = "";
  1066                 String pkgInfoContents = "";
  1067                 String contents = "";
  1069                 JavaFileObject pkgFileObj = null;
  1070                 JavaFileObject srcFileObj = null;
  1071                 Iterable<? extends JavaFileObject> files = null;
  1073                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1074                         + getExpectedContainer() + "\n";
  1075                 StringBuilder commonStmts = new StringBuilder();
  1077                 anno = Helper.ContentVars.REPEATABLEANNO.getVal();
  1078                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
  1079                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
  1080                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
  1081                         .append(Helper.ContentVars.REPEATABLE.getVal())
  1082                         .append(Helper.ContentVars.BASE.getVal())
  1083                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
  1084                         .append(Helper.ContentVars.CONTAINER.getVal());
  1085                 switch (srcType) {
  1086                     case PACKAGE:
  1087                         /*
  1088                         Sample package-info.java
  1089                         @ExpectedBase
  1090                         @ExpectedContainer
  1091                         @Foo() @Foo()
  1092                         package testpkg;
  1094                         @Retention(RetentionPolicy.RUNTIME)
  1095                         @Repeatable(FooContainer.class)
  1096                         @interface Foo {}
  1098                         @Retention(RetentionPolicy.RUNTIME)
  1099                         @interface FooContainer {
  1100                         Foo[] value();
  1103                         Sample testSrc:
  1104                         package testpkg;
  1105                         class A {}
  1106                          */
  1107                         testSrc = srcType.getTemplate().replace("#CN", className);
  1108                         contents = testSrc;
  1109                         srcFileObj = Helper.getFile(className, contents);
  1111                         replaceVal = expectedVals + "\n" + anno;
  1112                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
  1113                                 .replace("#REPLACE1", replaceVal)
  1114                                 .replace("#REPLACE2", commonStmts);
  1115                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
  1116                         files = Arrays.asList(pkgFileObj, srcFileObj);
  1117                         break;
  1118                     default:
  1119                         /*
  1120                         Sample testSrc for class:
  1121                         @Retention(RetentionPolicy.RUNTIME)
  1122                         @Repeatable(FooContainer.class)
  1123                         @interface Foo {}
  1125                         @Retention(RetentionPolicy.RUNTIME)
  1126                         @interface FooContainer {
  1127                         Foo[] value();
  1130                         @ExpectedBase
  1131                         @ExpectedContainer
  1132                         @Foo @Foo
  1133                         class A { }
  1134                          */
  1135                         replaceVal = expectedVals + anno;
  1136                         testSrc = srcType.getTemplate().replace("#CN", className)
  1137                                 .replace("#REPLACE", replaceVal);
  1138                         contents = commonStmts + testSrc;
  1139                         srcFileObj = Helper.getFile(className, contents);
  1140                         files = Arrays.asList(srcFileObj);
  1142                 return files;
  1144         },
  1145         BasicContainerRepeatable(
  1146         "@ExpectedBase(value=Foo.class, "
  1147                 + "getAnnotationVal = \"NULL\", "
  1148                 + "getAnnotationsVals = {"
  1149                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1150                 + "getDeclAnnosVals = {"
  1151                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"},"
  1152                 + "getDeclAnnoVal = \"NULL\","
  1153                 + "getAnnosArgs = {\"Foo\", \"Foo\"},"
  1154                 + "getDeclAnnosArgs = {\"Foo\", \"Foo\"})",
  1155         "@ExpectedContainer(value=FooContainer.class, "
  1156                 + "getAnnotationVal = \"FooContainer\","
  1157                 + "getAnnotationsVals = {"
  1158                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"},"
  1159                 + "getDeclAnnosVals = {"
  1160                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1161                 + "getDeclAnnoVal = \"FooContainer\","
  1162                 + "getAnnosArgs = {\"FooContainer\"},"
  1163                 + "getDeclAnnosArgs = {\"FooContainer\"} )") {
  1165             @Override
  1166             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1167                     String className) {
  1168                 String anno = "";
  1169                 String replaceVal = "";
  1170                 String testSrc = "";
  1171                 String pkgInfoContents = "";
  1172                 String contents = "";
  1174                 JavaFileObject pkgFileObj = null;
  1175                 JavaFileObject srcFileObj = null;
  1176                 Iterable<? extends JavaFileObject> files = null;
  1178                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1179                         + getExpectedContainer() + "\n";
  1180                 StringBuilder commonStmts = new StringBuilder();
  1182                 anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
  1183                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
  1184                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
  1185                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
  1186                         .append(Helper.ContentVars.REPEATABLE.getVal())
  1187                         .append(Helper.ContentVars.BASE.getVal())
  1188                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
  1189                         .append(Helper.ContentVars.CONTAINER.getVal());
  1190                 switch (srcType) {
  1191                     case PACKAGE:
  1192                         /*
  1193                         Sample package-info.java
  1194                         @ExpectedBase
  1195                         @ExpectedContainer
  1196                         @FooContainer(value = {@Foo, @Foo})
  1197                         package testpkg;
  1199                         @Retention(RetentionPolicy.RUNTIME)
  1200                         @Repeatable(FooContainer.class)
  1201                         @interface Foo {}
  1203                         @Retention(RetentionPolicy.RUNTIME)
  1204                         @interface FooContainer {
  1205                         Foo[] value();
  1208                         Sample testSrc:
  1209                         package testpkg;
  1210                         class A {}
  1211                          */
  1212                         testSrc = srcType.getTemplate().replace("#CN", className);
  1213                         contents = testSrc;
  1214                         srcFileObj = Helper.getFile(className, contents);
  1216                         replaceVal = expectedVals + "\n" + anno;
  1217                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
  1218                                 .replace("#REPLACE1", replaceVal)
  1219                                 .replace("#REPLACE2", commonStmts);
  1220                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
  1221                         files = Arrays.asList(pkgFileObj, srcFileObj);
  1222                         break;
  1223                     default:
  1224                         /*
  1225                         Sample testSrc for class:
  1226                         @Retention(RetentionPolicy.RUNTIME)
  1227                         @Repeatable(FooContainer.class)
  1228                         @interface Foo {}
  1230                         @Retention(RetentionPolicy.RUNTIME)
  1231                         @interface FooContainer {
  1232                         Foo[] value();
  1235                         @ExpectedBase
  1236                         @ExpectedContainer
  1237                         @FooContainer(value = {@Foo, @Foo})
  1238                         class A { }
  1239                          */
  1240                         replaceVal = expectedVals + anno;
  1241                         testSrc = srcType.getTemplate().replace("#CN", className)
  1242                                 .replace("#REPLACE", replaceVal);
  1243                         contents = commonStmts + testSrc;
  1244                         srcFileObj = Helper.getFile(className, contents);
  1245                         files = Arrays.asList(srcFileObj);
  1247                 return files;
  1249         },
  1250         BasicContainerRepeatable_Inherited(
  1251         "@ExpectedBase(value=Foo.class, "
  1252                 + "getAnnotationVal = \"NULL\", "
  1253                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1254                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
  1255                 + "getDeclAnnoVal = \"NULL\", "
  1256                 + "getAnnosArgs = {\"Foo\", \"Foo\"}, "
  1257                 + "getDeclAnnosArgs = {})",
  1258         "@ExpectedContainer(value=FooContainer.class, "
  1259                 + "getAnnotationVal = \"FooContainer\", "
  1260                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1261                 + "getDeclAnnosVals = { \"ExpectedBase\", \"ExpectedContainer\"}, "
  1262                 + "getDeclAnnoVal = \"NULL\", "
  1263                 + "getAnnosArgs = {\"FooContainer\"}, "
  1264                 + "getDeclAnnosArgs = {})") {
  1266             @Override
  1267             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1268                     String className) {
  1269                 String anno = "";
  1270                 String replaceVal = "";
  1271                 String contents = "";
  1272                 JavaFileObject srcFileObj = null;
  1273                 Iterable<? extends JavaFileObject> files = null;
  1275                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1276                         + getExpectedContainer() + "\n";
  1277                 StringBuilder commonStmts = getCommonStmts(true);
  1278                 /*
  1279                 Sample testSrc:
  1280                 @Retention(RetentionPolicy.RUNTIME)
  1281                 @Inherited
  1282                 @Repeatable(FooContainer.class)
  1283                 @interface Foo {}
  1285                 @Retention(RetentionPolicy.RUNTIME)
  1286                 @Inherited
  1287                 @interface FooContainer {
  1288                 Foo[] value();
  1291                 @FooContainer(value = {@Foo, @Foo})
  1292                 class SuperClass { }
  1294                 @ExpectedBase
  1295                 @ExpectedContainer
  1296                 class SubClass extends SuperClass { }
  1297                  */
  1298                 // @Inherited only works for classes, no switch cases for
  1299                 // method, field, package
  1300                 anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
  1302                 if (srcType == SrcType.CLASS) {
  1303                     // Contents for SuperClass
  1304                     replaceVal = commonStmts + "\n" + anno;
  1305                     String superClassContents = srcType.getTemplate()
  1306                             .replace("#CN", SUPERCLASS)
  1307                             .replace("#REPLACE", replaceVal);
  1309                     // Contents for SubClass that extends SuperClass
  1310                     replaceVal = expectedVals;
  1311                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1312                             .replace("#CN", className)
  1313                             .replace("#SN", SUPERCLASS)
  1314                             .replace("#REPLACE", replaceVal);
  1316                     contents = superClassContents + subClassContents;
  1317                     srcFileObj = Helper.getFile(className, contents);
  1318                     files = Arrays.asList(srcFileObj);
  1320                 return files;
  1322         },
  1323         RepeatableAnnoInherited(
  1324         "@ExpectedBase(value=Foo.class, "
  1325                 + "getAnnotationVal = \"NULL\", "
  1326                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1327                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\"}, "
  1328                 + // ignores inherited annotations
  1329                 "getDeclAnnoVal = \"NULL\", "
  1330                 + // ignores inherited
  1331                 "getAnnosArgs = {\"Foo\", \"Foo\"}, "
  1332                 + "getDeclAnnosArgs = {})", // ignores inherited
  1333         "@ExpectedContainer(value=FooContainer.class, "
  1334                 + "getAnnotationVal = \"FooContainer\", "
  1335                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1336                 + "getDeclAnnosVals = { \"ExpectedBase\", \"ExpectedContainer\"}, "
  1337                 + // ignores inherited annotations
  1338                 "getDeclAnnoVal = \"NULL\", "
  1339                 + // ignores inherited
  1340                 "getAnnosArgs = {\"FooContainer\"}, "
  1341                 + "getDeclAnnosArgs = {})") { // ignores inherited
  1343             @Override
  1344             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1345                     String className) {
  1346                 String anno = "";
  1347                 String replaceVal = "";
  1348                 String contents = "";
  1349                 JavaFileObject srcFileObj = null;
  1350                 Iterable<? extends JavaFileObject> files = null;
  1352                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1353                         + getExpectedContainer() + "\n";
  1354                 StringBuilder commonStmts = getCommonStmts(true);
  1355                 /*
  1356                 Sample testSrc:
  1357                 @Retention(RetentionPolicy.RUNTIME)
  1358                 @Inherited
  1359                 @Repeatable(FooContainer.class)
  1360                 @interface Foo {}
  1362                 @Retention(RetentionPolicy.RUNTIME)
  1363                 @Inherited
  1364                 @interface FooContainer {
  1365                 Foo[] value();
  1368                 @Foo() @Foo()
  1369                 class SuperClass { }
  1371                 @ExpectedBase
  1372                 @ExpectedContainer
  1373                 class SubClass extends SuperClass { }
  1374                  */
  1375                 // @Inherited only works for classes, no switch cases for
  1376                 // method, field, package
  1377                 anno = Helper.ContentVars.REPEATABLEANNO.getVal();
  1379                 if (srcType == SrcType.CLASS) {
  1380                     // Contents for SuperClass
  1381                     replaceVal = commonStmts + "\n" + anno;
  1382                     String superClassContents = srcType.getTemplate()
  1383                             .replace("#CN", SUPERCLASS)
  1384                             .replace("#REPLACE", replaceVal);
  1386                     // Contents for SubClass that extends SuperClass
  1387                     replaceVal = expectedVals;
  1388                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1389                             .replace("#CN", className)
  1390                             .replace("#SN", SUPERCLASS)
  1391                             .replace("#REPLACE", replaceVal);
  1393                     contents = superClassContents + subClassContents;
  1394                     srcFileObj = Helper.getFile(className, contents);
  1395                     files = Arrays.asList(srcFileObj);
  1397                 return files;
  1399         },
  1400         SingleAnnoWithContainer(
  1401         "@ExpectedBase(value=Foo.class, "
  1402                 + "getAnnotationVal = \"Foo\", "
  1403                 + "getAnnotationsVals = {"
  1404                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"},"
  1405                 + "getDeclAnnosVals = {"
  1406                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"},"
  1407                 + "getDeclAnnoVal = \"Foo\","
  1408                 + "getAnnosArgs = {\"Foo\", \"Foo\", \"Foo\"},"
  1409                 + "getDeclAnnosArgs = {\"Foo\", \"Foo\",\"Foo\"})",
  1410         "@ExpectedContainer(value=FooContainer.class, "
  1411                 + "getAnnotationVal = \"FooContainer\", "
  1412                 + "getAnnotationsVals = {"
  1413                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"},"
  1414                 + "getDeclAnnosVals = {"
  1415                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1416                 + "getDeclAnnoVal = \"FooContainer\","
  1417                 + "getDeclAnnosArgs = {\"FooContainer\"},"
  1418                 + "getAnnosArgs = {\"FooContainer\"})") {
  1420             @Override
  1421             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1422                     String className) {
  1423                 String anno = "";
  1424                 String replaceVal = "";
  1425                 String testSrc = "";
  1426                 String pkgInfoContents = "";
  1427                 String contents = "";
  1429                 JavaFileObject pkgFileObj = null;
  1430                 JavaFileObject srcFileObj = null;
  1431                 Iterable<? extends JavaFileObject> files = null;
  1433                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1434                         + getExpectedContainer() + "\n";
  1435                 StringBuilder commonStmts = new StringBuilder();
  1437                 anno = Helper.ContentVars.BASEANNO.getVal() + " "
  1438                         + Helper.ContentVars.LEGACYCONTAINER.getVal();
  1439                 commonStmts.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
  1440                         .append(Helper.ContentVars.IMPORTSTMTS.getVal())
  1441                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
  1442                         .append(Helper.ContentVars.REPEATABLE.getVal())
  1443                         .append(Helper.ContentVars.BASE.getVal())
  1444                         .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
  1445                         .append(Helper.ContentVars.CONTAINER.getVal());
  1446                 switch (srcType) {
  1447                     case PACKAGE:
  1448                         /*
  1449                         Sample package-info.java
  1450                         @ExpectedBase
  1451                         @ExpectedContainer
  1452                         @Foo @FooContainer(value = {@Foo, @Foo})
  1453                         package testpkg;
  1455                         @Retention(RetentionPolicy.RUNTIME)
  1456                         @Repeatable(FooContainer.class)
  1457                         @interface Foo {}
  1459                         @Retention(RetentionPolicy.RUNTIME)
  1460                         @interface FooContainer {
  1461                         Foo[] value();
  1464                         Sample testSrc:
  1465                         package testpkg;
  1466                         class A {}
  1467                          */
  1468                         testSrc = srcType.getTemplate().replace("#CN", className);
  1469                         contents = testSrc;
  1470                         srcFileObj = Helper.getFile(className, contents);
  1472                         replaceVal = expectedVals + "\n" + anno;
  1473                         pkgInfoContents = SrcType.PKGINFO.getTemplate()
  1474                                 .replace("#REPLACE1", replaceVal)
  1475                                 .replace("#REPLACE2", commonStmts);
  1476                         pkgFileObj = Helper.getFile(PKGINFONAME, pkgInfoContents);
  1477                         files = Arrays.asList(pkgFileObj, srcFileObj);
  1478                         break;
  1479                     default:
  1480                         /*
  1481                         Sample testSrc:
  1482                         @Retention(RetentionPolicy.RUNTIME)
  1483                         @Inherited
  1484                         @Repeatable(FooContainer.class)
  1485                         @interface Foo {}
  1487                         @Retention(RetentionPolicy.RUNTIME)
  1488                         @Inherited
  1489                         @interface FooContainer {
  1490                         Foo[] value();
  1493                         @ExpectedBase
  1494                         @ExpectedContainer
  1495                         @Foo @FooContainer(value = {@Foo, @Foo})
  1496                         class A { }
  1497                          */
  1498                         replaceVal = expectedVals + anno;
  1499                         testSrc = srcType.getTemplate()
  1500                                 .replace("#CN", className)
  1501                                 .replace("#REPLACE", replaceVal);
  1502                         contents = commonStmts + testSrc;
  1503                         srcFileObj = Helper.getFile(className, contents);
  1504                         files = Arrays.asList(srcFileObj);
  1506                 return files;
  1508         },
  1509         AnnoOnSuperAndSubClass_Inherited(
  1510         "@ExpectedBase(value=Foo.class, "
  1511                 + "getAnnotationVal = \"Foo\", "
  1512                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\" }, "
  1513                 + // override every annotation on superClass
  1514                 "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
  1515                 + // ignores inherited annotations
  1516                 "getDeclAnnoVal = \"Foo\", " // ignores inherited
  1517                 + "getAnnosArgs = {\"Foo\"}, "
  1518                 + "getDeclAnnosArgs = { \"Foo\" })", // ignores inherited
  1519         "@ExpectedContainer(value=FooContainer.class, "
  1520                 + "getAnnotationVal = \"NULL\", "
  1521                 + "getAnnotationsVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\" }, "
  1522                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
  1523                 + // ignores inherited annotations
  1524                 "getDeclAnnoVal = \"NULL\", " + // ignores inherited
  1525                 "getAnnosArgs = {}, " + "getDeclAnnosArgs = {})") {
  1527             @Override
  1528             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1529                     String className) {
  1530                 String anno = "";
  1531                 String replaceVal = "";
  1532                 String contents = "";
  1533                 JavaFileObject srcFileObj = null;
  1534                 Iterable<? extends JavaFileObject> files = null;
  1536                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1537                         + getExpectedContainer() + "\n";
  1538                 StringBuilder commonStmts = getCommonStmts(true);
  1540                 /*
  1541                 Sample testSrc:
  1542                 @Retention(RetentionPolicy.RUNTIME)
  1543                 @Inherited
  1544                 @Repeatable(FooContainer.class)
  1545                 @interface Foo {}
  1547                 @Retention(RetentionPolicy.RUNTIME)
  1548                 @Inherited
  1549                 @interface FooContainer {
  1550                 Foo[] value();
  1553                 @Foo()
  1554                 class SuperClass { }
  1556                 @ExpectedBase
  1557                 @ExpectedContainer
  1558                 @Foo
  1559                 class SubClass extends SuperClass { }
  1560                  */
  1561                 // @Inherited only works for classes, no switch cases for
  1562                 // method, field, package
  1564                 if (srcType == SrcType.CLASS) {
  1565                     // Contents for SuperClass
  1566                     anno = Helper.ContentVars.BASEANNO.getVal();
  1567                     replaceVal = commonStmts + "\n" + anno;
  1568                     String superClassContents = srcType.getTemplate()
  1569                             .replace("#CN", SUPERCLASS)
  1570                             .replace("#REPLACE", replaceVal);
  1572                     // Contents for SubClass that extends SuperClass
  1573                     replaceVal = expectedVals + "\n" + anno;
  1574                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1575                             .replace("#CN", className)
  1576                             .replace("#SN", SUPERCLASS)
  1577                             .replace("#REPLACE", replaceVal);
  1579                     contents = superClassContents + subClassContents;
  1580                     srcFileObj = Helper.getFile(className, contents);
  1581                     files = Arrays.asList(srcFileObj);
  1583                 return files;
  1585         },
  1586 //         // Testcase not working as expected, JDK-8004912
  1587 //         RepeatableOnSuperSingleOnSub_Inherited(
  1588 //         "@ExpectedBase(value=Foo.class, "
  1589 //                 + "getAnnotationVal = \"Foo\", "
  1590 //                 + "getAnnotationsVals = {"
  1591 //                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1592 //                 + //override every annotation on superClass
  1593 //                 "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
  1594 //                 + // ignores inherited annotations
  1595 //                 "getDeclAnnoVal = \"Foo\", " // ignores inherited
  1596 //                 + "getAnnosArgs = {\"Foo\"}, "
  1597 //                 + "getDeclAnnosArgs = { \"Foo\" })", // ignores inherited
  1598 //         "@ExpectedContainer(value=FooContainer.class, "
  1599 //                 + "getAnnotationVal = \"FooContainer\", "
  1600 //                 + "getAnnotationsVals = {"
  1601 //                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1602 //                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"}, "
  1603 //                 + // ignores inherited annotations
  1604 //                 "getDeclAnnoVal = \"NULL\", "
  1605 //                 + "getAnnosArgs = {\"FooContainer\"}, "
  1606 //                 + "getDeclAnnosArgs = {}) // ignores inherited ") {
  1608 //             @Override
  1609 //             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1610 //                     String className) {
  1611 //                 String anno = "";
  1612 //                 String replaceVal = "";
  1613 //                 String contents = "";
  1614 //                 JavaFileObject srcFileObj = null;
  1615 //                 Iterable<? extends JavaFileObject> files = null;
  1617 //                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1618 //                         + getExpectedContainer() + "\n";
  1619 //                 StringBuilder commonStmts = getCommonStmts(true);
  1621 //                 /*
  1622 //                 Sample testSrc:
  1623 //                 @Retention(RetentionPolicy.RUNTIME)
  1624 //                 @Inherited
  1625 //                 @Repeatable(FooContainer.class)
  1626 //                 @interface Foo {}
  1628 //                 @Retention(RetentionPolicy.RUNTIME)
  1629 //                 @Inherited
  1630 //                 @interface FooContainer {
  1631 //                 Foo[] value();
  1632 //                 }
  1634 //                 @Foo() @Foo
  1635 //                 class SuperClass { }
  1637 //                 @ExpectedBase
  1638 //                 @ExpectedContainer
  1639 //                 @Foo
  1640 //                 class SubClass extends SuperClass { }
  1641 //                  */
  1642 //                 //@Inherited only works for classes, no switch cases for method, field, package
  1644 //                 if (srcType == SrcType.CLASS) {
  1645 //                     //Contents for SuperClass
  1646 //                     anno = Helper.ContentVars.REPEATABLEANNO.getVal();
  1647 //                     replaceVal = commonStmts + "\n" + anno;
  1648 //                     String superClassContents = srcType.getTemplate()
  1649 //                             .replace("#CN", SUPERCLASS)
  1650 //                             .replace("#REPLACE", replaceVal);
  1652 //                     //Contents for SubClass that extends SuperClass
  1653 //                     anno = Helper.ContentVars.BASEANNO.getVal();
  1654 //                     replaceVal = expectedVals + "\n" + anno;
  1655 //                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1656 //                             .replace("#CN", className)
  1657 //                             .replace("#SN", SUPERCLASS)
  1658 //                             .replace("#REPLACE", replaceVal);
  1659 //                     contents = superClassContents + subClassContents;
  1660 //                     srcFileObj = Helper.getFile(className, contents);
  1661 //                     files = Arrays.asList(srcFileObj);
  1662 //                 }
  1663 //                 return files;
  1664 //             }
  1665 //         },
  1666 //         //Testcase not working as expected, JDK-8004912
  1667 //         SingleOnSuperRepeatableOnSub_Inherited(
  1668 //         "@ExpectedBase(value=Foo.class, "
  1669 //                 + "getAnnotationVal = \"Foo\", "
  1670 //                 + "getAnnotationsVals = {"
  1671 //                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1672 //                 + //override every annotation on superClass
  1673 //                 "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1674 //                 + // ignores inherited annotations
  1675 //                 "getDeclAnnoVal = \"NULL\","// ignores inherited
  1676 //                 + "getAnnosArgs = {\"Foo\", \"Foo\"}, "
  1677 //                 + "getDeclAnnosArgs = { \"Foo\", \"Foo\"})",
  1678 //         "@ExpectedContainer(value=FooContainer.class, "
  1679 //                 + "getAnnotationVal = \"FooContainer\", "
  1680 //                 + "getAnnotationsVals = {"
  1681 //                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1682 //                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"}, "
  1683 //                 + // ignores inherited annotations
  1684 //                 "getDeclAnnoVal = \"FooContainer\", "// ignores inherited
  1685 //                 + "getAnnosArgs = {\"FooContainer\"}, "
  1686 //                 + "getDeclAnnosArgs = {\"FooContainer\"})") {
  1688 //             @Override
  1689 //             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1690 //                     String className) {
  1691 //                 String anno = "";
  1692 //                 String replaceVal = "";
  1693 //                 String contents = "";
  1694 //                 JavaFileObject srcFileObj = null;
  1695 //                 Iterable<? extends JavaFileObject> files = null;
  1697 //                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1698 //                         + getExpectedContainer() + "\n";
  1699 //                 StringBuilder commonStmts = getCommonStmts(true);
  1701 //                 /*
  1702 //                 Sample testSrc:
  1703 //                 @Retention(RetentionPolicy.RUNTIME)
  1704 //                 @Inherited
  1705 //                 @Repeatable(FooContainer.class)
  1706 //                 @interface Foo {}
  1708 //                 @Retention(RetentionPolicy.RUNTIME)
  1709 //                 @Inherited
  1710 //                 @interface FooContainer {
  1711 //                 Foo[] value();
  1712 //                 }
  1714 //                 @Foo()
  1715 //                 class SuperClass { }
  1717 //                 @ExpectedBase
  1718 //                 @ExpectedContainer
  1719 //                 @Foo @Foo
  1720 //                 class SubClass extends SuperClass { }
  1721 //                  */
  1723 //                 //@Inherited only works for classes, no switch cases for method, field, package
  1724 //                 if (srcType == SrcType.CLASS) {
  1725 //                     //Contents for SuperClass
  1726 //                     anno = Helper.ContentVars.BASEANNO.getVal();
  1727 //                     replaceVal = commonStmts + "\n" + anno;
  1728 //                     String superClassContents = srcType.getTemplate()
  1729 //                             .replace("#CN", SUPERCLASS)
  1730 //                             .replace("#REPLACE", replaceVal);
  1732 //                     //Contents for SubClass that extends SuperClass
  1733 //                     anno = Helper.ContentVars.REPEATABLEANNO.getVal();
  1734 //                     replaceVal = expectedVals + "\n" + anno;
  1735 //                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1736 //                             .replace("#CN", className)
  1737 //                             .replace("#SN", SUPERCLASS)
  1738 //                             .replace("#REPLACE", replaceVal);
  1740 //                     contents = superClassContents + subClassContents;
  1741 //                     srcFileObj = Helper.getFile(className, contents);
  1742 //                     files = Arrays.asList(srcFileObj);
  1743 //                 }
  1744 //                 return files;
  1745 //             }
  1746 //         },
  1747 //         //Testcase not working as expected, JDK-8004912
  1748 //         ContainerOnSuperSingleOnSub_Inherited(
  1749 //         "@ExpectedBase(value=Foo.class, "
  1750 //                 + "getAnnotationVal = \"Foo\", "
  1751 //                 + "getAnnotationsVals = {"
  1752 //                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1753 //                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"},"
  1754 //                 + "getDeclAnnoVal = \"Foo\","
  1755 //                 + "getAnnosArgs = {\"Foo\"},"
  1756 //                 + "getDeclAnnosArgs = {\"Foo\"})",
  1757 //         "@ExpectedContainer(value=FooContainer.class, "
  1758 //                 + "getAnnotationVal = \"FooContainer\", "
  1759 //                 + "getAnnotationsVals = {"
  1760 //                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1761 //                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"},"
  1762 //                 + "getDeclAnnoVal = \"NULL\","
  1763 //                 + "getAnnosArgs = {\"FooContainer\"},"
  1764 //                 + "getDeclAnnosArgs = {})") {
  1766 //             @Override
  1767 //             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1768 //                     String className) {
  1769 //                 String anno = "";
  1770 //                 String replaceVal = "";
  1771 //                 String contents = "";
  1772 //                 JavaFileObject srcFileObj = null;
  1773 //                 Iterable<? extends JavaFileObject> files = null;
  1775 //                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1776 //                         + getExpectedContainer() + "\n";
  1777 //                 StringBuilder commonStmts = getCommonStmts(true);
  1779 //                 /*
  1780 //                 Sample testSrc:
  1781 //                 @Retention(RetentionPolicy.RUNTIME)
  1782 //                 @Inherited
  1783 //                 @Repeatable(FooContainer.class)
  1784 //                 @interface Foo {}
  1786 //                 @Retention(RetentionPolicy.RUNTIME)
  1787 //                 @Inherited
  1788 //                 @interface FooContainer {
  1789 //                 Foo[] value();
  1790 //                 }
  1792 //                 @FooContainer(value = {@Foo, @Foo})
  1793 //                 class SuperClass { }
  1795 //                 @ExpectedBase
  1796 //                 @ExpectedContainer
  1797 //                 @Foo
  1798 //                 class SubClass extends SuperClass { }
  1799 //                  */
  1801 //                 //@Inherited only works for classes, no switch cases for method, field, package
  1802 //                 if (srcType == SrcType.CLASS) {
  1803 //                     //Contents for SuperClass
  1804 //                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
  1805 //                     replaceVal = commonStmts + "\n" + anno;
  1806 //                     String superClassContents = srcType.getTemplate()
  1807 //                             .replace("#CN", SUPERCLASS)
  1808 //                             .replace("#REPLACE", replaceVal);
  1810 //                     //Contents for SubClass that extends SuperClass
  1811 //                     anno = Helper.ContentVars.BASEANNO.getVal();
  1812 //                     replaceVal = expectedVals + "\n" + anno;
  1813 //                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1814 //                             .replace("#CN", className)
  1815 //                             .replace("#SN", SUPERCLASS)
  1816 //                             .replace("#REPLACE", replaceVal);
  1818 //                     contents = superClassContents + subClassContents;
  1819 //                     srcFileObj = Helper.getFile(className, contents);
  1820 //                     files = Arrays.asList(srcFileObj);
  1821 //                 }
  1822 //                 return files;
  1823 //             }
  1824 //         },
  1825 //         // TestCase not working as expected, JDK-8004912
  1826 //         SingleOnSuperContainerOnSub_Inherited(
  1827 //         "@ExpectedBase(value=Foo.class, "
  1828 //                 + "getAnnotationVal = \"Foo\", "
  1829 //                 + "getAnnotationsVals = {"
  1830 //                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1831 //                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"},"
  1832 //                 + "getDeclAnnoVal = \"NULL\","
  1833 //                 + "getAnnosArgs = {\"Foo\", \"Foo\"},"
  1834 //                 + "getDeclAnnosArgs = {\"Foo\", \"Foo\"})",
  1835 //         "@ExpectedContainer(value=FooContainer.class, "
  1836 //                 + "getAnnotationVal = \"FooContainer\", "
  1837 //                 + "getAnnotationsVals = {"
  1838 //                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1839 //                 + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"FooContainer\"},"
  1840 //                 + "getDeclAnnoVal = \"FooContainer\","
  1841 //                 + "getAnnosArgs = {\"FooContainer\"},"
  1842 //                 + "getDeclAnnosArgs = {\"FooContainer\"})") {
  1844 //             @Override
  1845 //             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1846 //                     String className) {
  1847 //                 String anno = "";
  1848 //                 String replaceVal = "";
  1849 //                 String contents = "";
  1850 //                 JavaFileObject srcFileObj = null;
  1851 //                 Iterable<? extends JavaFileObject> files = null;
  1853 //                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1854 //                         + getExpectedContainer() + "\n";
  1855 //                 StringBuilder commonStmts = getCommonStmts(true);
  1857 //                 /*
  1858 //                 Sample testSrc:
  1859 //                 @Retention(RetentionPolicy.RUNTIME)
  1860 //                 @Inherited
  1861 //                 @Repeatable(FooContainer.class)
  1862 //                 @interface Foo {}
  1864 //                 @Retention(RetentionPolicy.RUNTIME)
  1865 //                 @Inherited
  1866 //                 @interface FooContainer {
  1867 //                 Foo[] value();
  1868 //                 }
  1870 //                 @Foo
  1871 //                 class SuperClass { }
  1873 //                 @ExpectedBase
  1874 //                 @ExpectedContainer
  1875 //                 @FooContainer(value = {@Foo, @Foo})
  1876 //                 class SubClass extends SuperClass { }
  1877 //                  */
  1879 //                 //@Inherited only works for classes, no switch cases for method, field, package
  1880 //                 if (srcType == SrcType.CLASS) {
  1881 //                     //Contents for SuperClass
  1882 //                     anno = Helper.ContentVars.BASEANNO.getVal();
  1883 //                     replaceVal = commonStmts + "\n" + anno;
  1884 //                     String superClassContents = srcType.getTemplate()
  1885 //                             .replace("#CN", SUPERCLASS)
  1886 //                             .replace("#REPLACE", replaceVal);
  1888 //                     //Contents for SubClass that extends SuperClass
  1889 //                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal();
  1890 //                     replaceVal = expectedVals + "\n" + anno;
  1891 //                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1892 //                             .replace("#CN", className)
  1893 //                             .replace("#SN", SUPERCLASS)
  1894 //                             .replace("#REPLACE", replaceVal);
  1896 //                     contents = superClassContents + subClassContents;
  1897 //                     srcFileObj = Helper.getFile(className, contents);
  1898 //                     files = Arrays.asList(srcFileObj);
  1899 //                 }
  1900 //                 return files;
  1901 //             }
  1902 //         },
  1903         SingleOnSuperContainerAndSingleOnSub_Inherited(
  1904         "@ExpectedBase(value=Foo.class, "
  1905                 + "getAnnotationVal = \"Foo\", "
  1906                 + "getAnnotationsVals = {"
  1907                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1908                 + "getDeclAnnosVals = {"
  1909                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"},"
  1910                 + "getDeclAnnoVal = \"Foo\","
  1911                 + "getAnnosArgs = {\"Foo\", \"Foo\", \"Foo\"},"
  1912                 + "getDeclAnnosArgs = {\"Foo\", \"Foo\", \"Foo\"})",
  1913         "@ExpectedContainer(value=FooContainer.class, "
  1914                 + "getAnnotationVal = \"FooContainer\", "
  1915                 + "getAnnotationsVals = {"
  1916                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1917                 + "getDeclAnnosVals = {"
  1918                 +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"},"
  1919                 + "getDeclAnnoVal = \"FooContainer\","
  1920                 + "getAnnosArgs = {\"FooContainer\"},"
  1921                 + "getDeclAnnosArgs = {\"FooContainer\"})") {
  1923             @Override
  1924             public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  1925                     String className) {
  1926                 String anno = "";
  1927                 String replaceVal = "";
  1928                 String contents = "";
  1929                 JavaFileObject srcFileObj = null;
  1930                 Iterable<? extends JavaFileObject> files = null;
  1931                 String expectedVals = "\n" + getExpectedBase() + "\n"
  1932                         + getExpectedContainer() + "\n";
  1933                 StringBuilder commonStmts = getCommonStmts(true);
  1935                 /*
  1936                 Sample testSrc:
  1937                 @Retention(RetentionPolicy.RUNTIME)
  1938                 @Inherited
  1939                 @interface Foo {}
  1941                 @Retention(RetentionPolicy.RUNTIME)
  1942                 @Inherited
  1943                 @Repeatable(FooContainer.class)
  1944                 @interface FooContainer {
  1945                 Foo[] value();
  1948                 @Foo
  1949                 class SuperClass { }
  1951                 @ExpectedBase
  1952                 @ExpectedContainer
  1953                 @FooContainer(value = {@Foo, @Foo}) @Foo
  1954                 class SubClass extends SuperClass {}
  1955                  */
  1957                 if (srcType == SrcType.CLASS) {
  1958                     //Contents for SuperClass
  1959                     anno = Helper.ContentVars.BASEANNO.getVal();
  1960                     replaceVal = commonStmts + "\n" + anno;
  1961                     String superClassContents = srcType.getTemplate()
  1962                             .replace("#CN", SUPERCLASS)
  1963                             .replace("#REPLACE", replaceVal);
  1965                     //Contents for SubClass that extends SuperClass
  1966                     anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
  1967                             + Helper.ContentVars.BASEANNO.getVal();
  1968                     replaceVal = expectedVals + "\n" + anno;
  1969                     String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  1970                             .replace("#CN", className)
  1971                             .replace("#SN", SUPERCLASS)
  1972                             .replace("#REPLACE", replaceVal);
  1974                     contents = superClassContents + subClassContents;
  1975                     srcFileObj = Helper.getFile(className, contents);
  1976                     files = Arrays.asList(srcFileObj);
  1978                 return files;
  1980         },
  1981 //          // TestCase not working as expected, JDK-8004912
  1982 //          ContainerAndSingleOnSuperSingleOnSub_Inherited(
  1983 //          "@ExpectedBase(value=Foo.class, "
  1984 //                  + "getAnnotationVal = \"Foo\", "
  1985 //                  + "getAnnotationsVals = {"
  1986 //                  +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1987 //                  + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"},"
  1988 //                  + "getDeclAnnoVal = \"Foo\","
  1989 //                  + "getAnnosArgs = {\"Foo\"},"
  1990 //                  + "getDeclAnnosArgs = {\"Foo\"})",
  1991 //          "@ExpectedContainer(value=FooContainer.class, "
  1992 //                  + "getAnnotationVal = \"FooContainer\", "
  1993 //                  + "getAnnotationsVals = {"
  1994 //                  +       "\"ExpectedBase\", \"ExpectedContainer\", \"Foo\", \"FooContainer\"}, "
  1995 //                  + "getDeclAnnosVals = {\"ExpectedBase\", \"ExpectedContainer\", \"Foo\"},"
  1996 //                  + "getDeclAnnoVal = \"NULL\","
  1997 //                  + "getAnnosArgs = {\"FooContainer\"},"
  1998 //                  + "getDeclAnnosArgs = {})") {
  2000 //              @Override
  2001 //              public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  2002 //                      String className) {
  2003 //                  String anno = "";
  2004 //                  String replaceVal = "";
  2005 //                  String contents = "";
  2006 //                  JavaFileObject srcFileObj = null;
  2007 //                  Iterable<? extends JavaFileObject> files = null;
  2009 //                  String expectedVals = "\n" + getExpectedBase() + "\n"
  2010 //                          + getExpectedContainer() + "\n";
  2011 //                  StringBuilder commonStmts = getCommonStmts(true);
  2013 //                  /*
  2014 //                  Sample testSrc:
  2015 //                  @Retention(RetentionPolicy.RUNTIME)
  2016 //                  @Inherited
  2017 //                  @Repeatable(FooContainer.class)
  2018 //                  @interface Foo {}
  2020 //                  @Retention(RetentionPolicy.RUNTIME)
  2021 //                  @Inherited
  2022 //                  @interface FooContainer {
  2023 //                  Foo[] value();
  2024 //                  }
  2026 //                  @FooContainer(value = {@Foo, @Foo})
  2027 //                  @Foo
  2028 //                  class SuperClass { }
  2030 //                  @ExpectedBase
  2031 //                  @ExpectedContainer
  2032 //                  @Foo
  2033 //                  class SubClass extends SuperClass { }
  2034 //                   */
  2036 //                  //@Inherited only works for classes, no switch cases for method, field, package
  2037 //                  if (srcType == SrcType.CLASS) {
  2038 //                      //Contents for SuperClass
  2039 //                      anno = Helper.ContentVars.LEGACYCONTAINER.getVal()
  2040 //                              + Helper.ContentVars.BASEANNO.getVal();
  2041 //                      replaceVal = commonStmts + "\n" + anno;
  2042 //                      String superClassContents = srcType.getTemplate()
  2043 //                              .replace("#CN", SUPERCLASS)
  2044 //                              .replace("#REPLACE", replaceVal);
  2046 //                      //Contents for SubClass that extends SuperClass
  2047 //                      anno = Helper.ContentVars.BASEANNO.getVal();
  2048 //                      replaceVal = expectedVals + "\n" + anno;
  2049 //                      String subClassContents = SrcType.CLASSEXTENDS.getTemplate()
  2050 //                              .replace("#CN", className)
  2051 //                              .replace("#SN", SUPERCLASS)
  2052 //                              .replace("#REPLACE", replaceVal);
  2054 //                      contents = superClassContents + subClassContents;
  2055 //                      srcFileObj = Helper.getFile(className, contents);
  2056 //                      files = Arrays.asList(srcFileObj);
  2057 //                  }
  2058 //                  return files;
  2059 //              }
  2060 //         }
  2062          private String expectedBase, expectedContainer;
  2064          private TestCase(String expectedBase, String expectedContainer) {
  2065              this.expectedBase = expectedBase;
  2066              this.expectedContainer = expectedContainer;
  2069          public String getExpectedBase() {
  2070              return expectedBase;
  2073          public String getExpectedContainer() {
  2074              return expectedContainer;
  2077          // Each enum element should override this method
  2078          public Iterable<? extends JavaFileObject> getTestFiles(SrcType srcType,
  2079                  String className) {
  2080              return null;
  2084     /*
  2085      * Each srctype has its template defined used for test src generation
  2086      * Primary src types: class, method, field, package define
  2087      *                    getExpectedBase() and getExpectedContainer()
  2088      */
  2089     enum SrcType {
  2091         CLASS("\n#REPLACE\nclass #CN { } ") {
  2093             @Override
  2094             public ExpectedBase getExpectedBase(Class<?> c) {
  2095                 return c.getAnnotation(ExpectedBase.class);
  2098             @Override
  2099             public ExpectedContainer getExpectedContainer(Class<?> c) {
  2100                 return c.getAnnotation(ExpectedContainer.class);
  2102         },
  2103         METHOD("class #CN  {\n" + "   " + "#REPLACE\n" + "   void "
  2104         + TESTMETHOD + "() {} \n" + "}\n") {
  2106             @Override
  2107             public ExpectedBase getExpectedBase(Class<?> c) {
  2108                 ExpectedBase ret = null;
  2109                 try {
  2110                     ret = c.getDeclaredMethod(TESTMETHOD).getAnnotation(
  2111                             ExpectedBase.class);
  2112                 } catch (NoSuchMethodException nme) {
  2113                     error("Could not get " + TESTMETHOD + " for className "
  2114                             + c.getName() + " Exception:\n" + nme);
  2116                 return ret;
  2119             @Override
  2120             public ExpectedContainer getExpectedContainer(Class<?> c) {
  2121                 ExpectedContainer ret = null;
  2122                 try {
  2123                     ret = c.getDeclaredMethod(TESTMETHOD).getAnnotation(
  2124                             ExpectedContainer.class);
  2125                 } catch (NoSuchMethodException nme) {
  2126                     error("Could not get " + TESTMETHOD + " for className "
  2127                             + c.getName() + " Exception:\n" + nme);
  2129                 return ret;
  2132         },
  2133         FIELD("class #CN  {\n" + "   " + "#REPLACE\n" + "   int " + TESTFIELD
  2134         + " = 0; \n" + "}\n") {
  2136             @Override
  2137             public ExpectedBase getExpectedBase(Class<?> c) {
  2138                 ExpectedBase ret = null;
  2139                 try {
  2140                     ret = c.getDeclaredField(TESTFIELD).getAnnotation(
  2141                             ExpectedBase.class);
  2142                 } catch (NoSuchFieldException nme) {
  2143                     error("Could not get " + TESTFIELD + " for className "
  2144                             + c.getName() + " Exception:\n" + nme);
  2146                 return ret;
  2149             @Override
  2150             public ExpectedContainer getExpectedContainer(Class<?> c) {
  2151                 ExpectedContainer ret = null;
  2152                 try {
  2153                     ret = c.getDeclaredField(TESTFIELD).getAnnotation(
  2154                             ExpectedContainer.class);
  2155                 } catch (NoSuchFieldException nme) {
  2156                     error("Could not get " + TESTFIELD + " for className "
  2157                             + c.getName() + " Exception:\n" + nme);
  2159                 return ret;
  2162         },
  2163         PACKAGE("package " + TESTPKG + "; \n" + "class #CN {}") {
  2165             @Override
  2166             public ExpectedBase getExpectedBase(Class<?> c) {
  2167                 return c.getPackage().getAnnotation(ExpectedBase.class);
  2170             @Override
  2171             public ExpectedContainer getExpectedContainer(Class<?> c) {
  2172                 return c.getPackage().getAnnotation(ExpectedContainer.class);
  2174         },
  2175         PKGINFO("#REPLACE1\npackage " + TESTPKG + "; \n" + "#REPLACE2"),
  2176         INTERFACE("#REPLACE\ninterface #IN { } "),
  2177         INTERFACEIMPL("#REPLACE\nclass #CN implements #IN {}"),
  2178         CLASSEXTENDS("#REPLACE\nclass #CN extends #SN {}");
  2179         String template;
  2181         private SrcType(String template) {
  2182             this.template = template;
  2185         public String getTemplate() {
  2186             return template;
  2189         // Elements should override
  2190         public ExpectedBase getExpectedBase(Class<?> c) {
  2191             return null;
  2194         public ExpectedContainer getExpectedContainer(Class<?> c) {
  2195             return null;
  2198         /*
  2199          * Returns only primary src types ;
  2200          */
  2201         public static SrcType[] getSrcTypes() {
  2202             return new SrcType[]{CLASS, PACKAGE, METHOD, FIELD};
  2206     /*
  2207      * Each enum constant is one of the 6 methods from AnnotatedElement interface
  2208      * that needs to be tested.
  2209      * Each enum constant overrides these 4 methods:
  2210      * - getActualAnnoBase(SrcType srcType, Class<?> c)
  2211      * - getActualAnnoContainer(SrcType srcType, Class<?> c)
  2212      * - getExpectedAnnoBase(SrcType srcType, Class<?> c)
  2213      * - getExpectedAnnoContainer(SrcType srcType, Class<?> c)
  2214      */
  2215     enum TestMethod {
  2217         GET_ANNO("getAnnotation") {
  2219             @Override
  2220             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
  2221                 Annotation[] actualAnno = new Annotation[1];
  2222                 switch (srcType) {
  2223                     case CLASS:
  2224                         actualAnno[0] = c.getAnnotation(srcType.getExpectedBase(c).value());
  2225                         break;
  2226                     case PACKAGE:
  2227                         actualAnno[0] = c.getPackage().getAnnotation(
  2228                                 srcType.getExpectedBase(c).value());
  2229                         break;
  2230                     case METHOD:
  2231                         try {
  2232                             actualAnno[0] = c.getDeclaredMethod(TESTMETHOD).getAnnotation(
  2233                                     srcType.getExpectedBase(c).value());
  2234                         } catch (NoSuchMethodException nme) {
  2235                             error("Could not get " + TESTMETHOD
  2236                                     + " for className = " + c.getName()
  2237                                     + "Exception = " + nme);
  2239                         break;
  2240                     case FIELD:
  2241                         try {
  2242                             actualAnno[0] = c.getDeclaredField(TESTFIELD).getAnnotation(
  2243                                     srcType.getExpectedBase(c).value());
  2244                         } catch (NoSuchFieldException nfe) {
  2245                             error("Could not get " + TESTFIELD
  2246                                     + " for className = " + c.getName()
  2247                                     + "Exception = " + nfe);
  2249                         break;
  2251                 return actualAnno;
  2254             @Override
  2255             public Annotation[] getActualAnnoContainer(SrcType srcType,
  2256                     Class<?> c) {
  2257                 Annotation[] actualAnno = new Annotation[1];
  2258                 switch (srcType) {
  2259                     case CLASS:
  2260                         actualAnno[0] = c.getAnnotation(srcType.getExpectedContainer(c).value());
  2261                         break;
  2262                     case PACKAGE:
  2263                         actualAnno[0] = c.getPackage().getAnnotation(
  2264                                 srcType.getExpectedContainer(c).value());
  2265                         break;
  2266                     case METHOD:
  2267                         try {
  2268                             actualAnno[0] = c.getDeclaredMethod(TESTMETHOD).getAnnotation(
  2269                                     srcType.getExpectedContainer(c).value());
  2270                         } catch (NoSuchMethodException nme) {
  2271                             error("Could not get " + TESTMETHOD
  2272                                     + " for className = " + c.getName()
  2273                                     + "Exception = " + nme);
  2275                         break;
  2276                     case FIELD:
  2277                         try {
  2278                             actualAnno[0] = c.getDeclaredField(TESTFIELD).getAnnotation(
  2279                                     srcType.getExpectedContainer(c).value());
  2280                         } catch (NoSuchFieldException nfe) {
  2281                             error("Could not get " + TESTFIELD
  2282                                     + " for className = " + c.getName()
  2283                                     + "Exception = " + nfe);
  2285                         break;
  2287                 return actualAnno;
  2290             @Override
  2291             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
  2292                 String[] expAnno = {srcType.getExpectedBase(c).getAnnotationVal()};
  2293                 return expAnno;
  2296             @Override
  2297             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
  2298                 String[] expAnno = {srcType.getExpectedContainer(c).getAnnotationVal()};
  2299                 return expAnno;
  2301         },
  2302         GET_ANNOS("getAnnotations") {
  2304             @Override
  2305             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
  2306                 Annotation[] actualAnnos = null;
  2307                 switch (srcType) {
  2308                     case CLASS:
  2309                         actualAnnos = c.getAnnotations();
  2310                         break;
  2311                     case PACKAGE:
  2312                         actualAnnos = c.getPackage().getAnnotations();
  2313                         break;
  2314                     case METHOD:
  2315                         try {
  2316                             actualAnnos = c.getDeclaredMethod(TESTMETHOD).getAnnotations();
  2317                         } catch (NoSuchMethodException nme) {
  2318                             error("Could not get " + TESTMETHOD
  2319                                     + " for className = " + c.getName()
  2320                                     + "Exception = " + nme);
  2322                         break;
  2323                     case FIELD:
  2324                         try {
  2325                             actualAnnos = c.getDeclaredField(TESTFIELD).getAnnotations();
  2326                         } catch (NoSuchFieldException nfe) {
  2327                             error("Could not get " + TESTFIELD
  2328                                     + " for className = " + c.getName()
  2329                                     + "Exception = " + nfe);
  2331                         break;
  2333                 return actualAnnos;
  2336             @Override
  2337             public Annotation[] getActualAnnoContainer(SrcType srcType,
  2338                     Class<?> c) {
  2339                 Annotation[] actualAnnos = null;
  2340                 switch (srcType) {
  2341                     case CLASS:
  2342                         actualAnnos = c.getAnnotations();
  2343                         break;
  2344                     case PACKAGE:
  2345                         actualAnnos = c.getPackage().getAnnotations();
  2346                         break;
  2347                     case METHOD:
  2348                         try {
  2349                             actualAnnos = c.getDeclaredMethod(TESTMETHOD).getAnnotations();
  2350                         } catch (NoSuchMethodException nme) {
  2351                             error("Could not get " + TESTMETHOD
  2352                                     + " for className = " + c.getName()
  2353                                     + "Exception = " + nme);
  2355                         break;
  2356                     case FIELD:
  2357                         try {
  2358                             actualAnnos = c.getDeclaredField(TESTFIELD).getAnnotations();
  2359                         } catch (NoSuchFieldException nfe) {
  2360                             error("Could not get " + TESTFIELD
  2361                                     + " for className = " + c.getName()
  2362                                     + "Exception = " + nfe);
  2364                         break;
  2366                 return actualAnnos;
  2369             @Override
  2370             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
  2371                 return srcType.getExpectedBase(c).getAnnotationsVals();
  2374             @Override
  2375             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
  2376                 return srcType.getExpectedContainer(c).getAnnotationsVals();
  2378         },
  2379         GET_DECL_ANNOS("getDeclaredAnnotations") {
  2381             @Override
  2382             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
  2383                 Annotation[] actualDeclAnnos = null;
  2384                 switch (srcType) {
  2385                     case CLASS:
  2386                         actualDeclAnnos = c.getDeclaredAnnotations();
  2387                         break;
  2388                     case PACKAGE:
  2389                         actualDeclAnnos = c.getPackage().getDeclaredAnnotations();
  2390                         break;
  2391                     case METHOD:
  2392                         try {
  2393                             actualDeclAnnos = c.getDeclaredMethod(TESTMETHOD)
  2394                                     .getDeclaredAnnotations();
  2395                         } catch (NoSuchMethodException nme) {
  2396                             error("Could not get " + TESTMETHOD
  2397                                     + " for className = " + c.getName()
  2398                                     + "Exception = " + nme);
  2400                         break;
  2401                     case FIELD:
  2402                         try {
  2403                             actualDeclAnnos = c.getDeclaredField(TESTFIELD)
  2404                                     .getDeclaredAnnotations();
  2405                         } catch (NoSuchFieldException nfe) {
  2406                             error("Could not get " + TESTFIELD
  2407                                     + " for className = " + c.getName()
  2408                                     + "Exception = " + nfe);
  2410                         break;
  2412                 return actualDeclAnnos;
  2415             @Override
  2416             public Annotation[] getActualAnnoContainer(SrcType srcType,
  2417                     Class<?> c) {
  2418                 Annotation[] actualDeclAnnos = null;
  2419                 switch (srcType) {
  2420                     case CLASS:
  2421                         actualDeclAnnos = c.getDeclaredAnnotations();
  2422                         break;
  2423                     case PACKAGE:
  2424                         actualDeclAnnos = c.getPackage().getDeclaredAnnotations();
  2425                         break;
  2426                     case METHOD:
  2427                         try {
  2428                             actualDeclAnnos = c.getDeclaredMethod(TESTMETHOD)
  2429                                     .getDeclaredAnnotations();
  2430                         } catch (NoSuchMethodException nme) {
  2431                             error("Could not get " + TESTMETHOD
  2432                                     + " for className = " + c.getName()
  2433                                     + "Exception = " + nme);
  2435                         break;
  2436                     case FIELD:
  2437                         try {
  2438                             actualDeclAnnos = c.getDeclaredField(TESTFIELD)
  2439                                     .getDeclaredAnnotations();
  2440                         } catch (NoSuchFieldException nfe) {
  2441                             error("Could not get " + TESTFIELD
  2442                                     + " for className = " + c.getName()
  2443                                     + "Exception = " + nfe);
  2445                         break;
  2447                 return actualDeclAnnos;
  2450             @Override
  2451             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
  2452                 return srcType.getExpectedBase(c).getDeclAnnosVals();
  2455             @Override
  2456             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
  2457                 return srcType.getExpectedContainer(c).getDeclAnnosVals();
  2459         },
  2460         GET_DECL_ANNO("getDeclaredAnnotation") {
  2462             @Override
  2463             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
  2464                 Annotation[] actualDeclAnno = new Annotation[1];
  2465                 switch (srcType) {
  2466                     case CLASS:
  2467                         actualDeclAnno[0] = c.getDeclaredAnnotation(
  2468                                 srcType.getExpectedBase(c).value());
  2469                         break;
  2470                     case PACKAGE:
  2471                         actualDeclAnno[0] = c.getPackage().getDeclaredAnnotation(
  2472                                 srcType.getExpectedBase(c).value());
  2473                         break;
  2474                     case METHOD:
  2475                         try {
  2476                             actualDeclAnno[0] = c.getDeclaredMethod(TESTMETHOD)
  2477                                     .getDeclaredAnnotation(
  2478                                         srcType.getExpectedBase(c).value());
  2479                         } catch (NoSuchMethodException nme) {
  2480                             error("Could not get " + TESTMETHOD
  2481                                     + " for className = " + c.getName()
  2482                                     + "Exception = " + nme);
  2484                         break;
  2485                     case FIELD:
  2486                         try {
  2487                             actualDeclAnno[0] = c.getDeclaredField(TESTFIELD)
  2488                                     .getDeclaredAnnotation(
  2489                                         srcType.getExpectedBase(c).value());
  2490                         } catch (NoSuchFieldException nfe) {
  2491                             error("Could not get " + TESTFIELD
  2492                                     + " for className = " + c.getName()
  2493                                     + "Exception = " + nfe);
  2495                         break;
  2497                 return actualDeclAnno;
  2500             @Override
  2501             public Annotation[] getActualAnnoContainer(SrcType srcType,
  2502                     Class<?> c) {
  2503                 Annotation[] actualDeclAnno = new Annotation[1];
  2504                 switch (srcType) {
  2505                     case CLASS:
  2506                         actualDeclAnno[0] = c.getDeclaredAnnotation(
  2507                                 srcType.getExpectedContainer(c).value());
  2508                         break;
  2509                     case PACKAGE:
  2510                         actualDeclAnno[0] = c.getPackage().getDeclaredAnnotation(
  2511                                 srcType.getExpectedContainer(c).value());
  2512                         break;
  2513                     case METHOD:
  2514                         try {
  2515                             actualDeclAnno[0] = c.getDeclaredMethod(TESTMETHOD)
  2516                                     .getDeclaredAnnotation(
  2517                                         srcType.getExpectedContainer(c).value());
  2518                         } catch (NoSuchMethodException nme) {
  2519                             error("Could not get " + TESTMETHOD
  2520                                     + " for className = " + c.getName()
  2521                                     + "Exception = " + nme);
  2523                         break;
  2524                     case FIELD:
  2525                         try {
  2526                             actualDeclAnno[0] = c.getDeclaredField(TESTFIELD)
  2527                                     .getDeclaredAnnotation(
  2528                                         srcType.getExpectedContainer(c).value());
  2529                         } catch (NoSuchFieldException nfe) {
  2530                             error("Could not get " + TESTFIELD
  2531                                     + " for className = " + c.getName()
  2532                                     + "Exception = " + nfe);
  2534                         break;
  2536                 return actualDeclAnno;
  2539             @Override
  2540             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
  2541                 String[] expAnno = {srcType.getExpectedBase(c).getDeclAnnoVal()};
  2542                 return expAnno;
  2545             @Override
  2546             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
  2547                 String[] expAnno = {srcType.getExpectedContainer(c).getDeclAnnoVal()};
  2548                 return expAnno;
  2550         }, // new
  2551         GET_ANNOS_ARG("getAnnotationsArg") {
  2553             @Override
  2554             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
  2555                 Annotation[] actualAnnoArgs = null;
  2556                 switch (srcType) {
  2557                     case CLASS:
  2558                         actualAnnoArgs = c.getAnnotationsByType(srcType.getExpectedBase(c).value());
  2559                         break;
  2560                     case PACKAGE:
  2561                         actualAnnoArgs = c.getPackage().getAnnotationsByType(
  2562                                 srcType.getExpectedBase(c).value());
  2563                         break;
  2564                     case METHOD:
  2565                         try {
  2566                             actualAnnoArgs = c.getDeclaredMethod(TESTMETHOD)
  2567                                     .getAnnotationsByType(
  2568                                         srcType.getExpectedBase(c).value());
  2569                         } catch (NoSuchMethodException nme) {
  2570                             error("Could not get " + TESTMETHOD
  2571                                     + " for className = " + c.getName()
  2572                                     + "Exception = " + nme);
  2574                         break;
  2575                     case FIELD:
  2576                         try {
  2577                             actualAnnoArgs = c.getDeclaredField(TESTFIELD)
  2578                                     .getAnnotationsByType(
  2579                                         srcType.getExpectedBase(c).value());
  2580                         } catch (NoSuchFieldException nfe) {
  2581                             error("Could not get " + TESTFIELD
  2582                                     + " for className = " + c.getName()
  2583                                     + "Exception = " + nfe);
  2585                         break;
  2587                 return actualAnnoArgs;
  2590             @Override
  2591             public Annotation[] getActualAnnoContainer(SrcType srcType,
  2592                     Class<?> c) {
  2593                 Annotation[] actualAnnoArgs = null;
  2594                 switch (srcType) {
  2595                     case CLASS:
  2596                         actualAnnoArgs = c.getAnnotationsByType(srcType.getExpectedContainer(c).value());
  2597                         break;
  2598                     case PACKAGE:
  2599                         actualAnnoArgs = c.getPackage().getAnnotationsByType(
  2600                                 srcType.getExpectedContainer(c).value());
  2601                         break;
  2602                     case METHOD:
  2603                         try {
  2604                             actualAnnoArgs = c.getDeclaredMethod(TESTMETHOD)
  2605                                     .getAnnotationsByType(
  2606                                         srcType.getExpectedContainer(c).value());
  2607                         } catch (NoSuchMethodException nme) {
  2608                             error("Could not get " + TESTMETHOD
  2609                                     + " for className = " + c.getName()
  2610                                     + "Exception = " + nme);
  2612                         break;
  2613                     case FIELD:
  2614                         try {
  2615                             actualAnnoArgs = c.getDeclaredField(TESTFIELD)
  2616                                     .getAnnotationsByType(
  2617                                         srcType.getExpectedContainer(c).value());
  2618                         } catch (NoSuchFieldException nfe) {
  2619                             error("Could not get " + TESTFIELD
  2620                                     + " for className = " + c.getName()
  2621                                     + "Exception = " + nfe);
  2623                         break;
  2625                 return actualAnnoArgs;
  2628             @Override
  2629             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
  2630                 return srcType.getExpectedBase(c).getAnnosArgs();
  2633             @Override
  2634             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
  2635                 return srcType.getExpectedContainer(c).getAnnosArgs();
  2637         }, // new
  2638         GET_DECL_ANNOS_ARG("getDeclAnnosArg") {
  2640             @Override
  2641             public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
  2642                 Annotation[] actualDeclAnnosArgs = null;
  2643                 switch (srcType) {
  2644                     case CLASS:
  2645                         actualDeclAnnosArgs = c.getDeclaredAnnotationsByType(
  2646                                 srcType.getExpectedBase(c).value());
  2647                         break;
  2648                     case PACKAGE:
  2649                         actualDeclAnnosArgs = c.getPackage().getDeclaredAnnotationsByType(
  2650                                 srcType.getExpectedBase(c).value());
  2651                         break;
  2652                     case METHOD:
  2653                         try {
  2654                             actualDeclAnnosArgs = c.getDeclaredMethod(TESTMETHOD)
  2655                                     .getDeclaredAnnotationsByType(
  2656                                         srcType.getExpectedBase(c).value());
  2657                         } catch (NoSuchMethodException nme) {
  2658                             error("Could not get " + TESTMETHOD
  2659                                     + " for className = " + c.getName()
  2660                                     + "Exception = " + nme);
  2662                         break;
  2663                     case FIELD:
  2664                         try {
  2665                             actualDeclAnnosArgs = c.getDeclaredField(TESTFIELD)
  2666                                     .getDeclaredAnnotationsByType(
  2667                                         srcType.getExpectedBase(c).value());
  2668                         } catch (NoSuchFieldException nfe) {
  2669                             error("Could not get " + TESTFIELD
  2670                                     + " for className = " + c.getName()
  2671                                     + "Exception = " + nfe);
  2673                         break;
  2675                 return actualDeclAnnosArgs;
  2678             @Override
  2679             public Annotation[] getActualAnnoContainer(SrcType srcType,
  2680                     Class<?> c) {
  2681                 Annotation[] actualDeclAnnosArgs = null;
  2682                 switch (srcType) {
  2683                     case CLASS:
  2684                         actualDeclAnnosArgs = c.getDeclaredAnnotationsByType(
  2685                                 srcType.getExpectedContainer(c).value());
  2686                         break;
  2687                     case PACKAGE:
  2688                         actualDeclAnnosArgs = c.getPackage().getDeclaredAnnotationsByType(
  2689                                 srcType.getExpectedContainer(c).value());
  2690                         break;
  2691                     case METHOD:
  2692                         try {
  2693                             actualDeclAnnosArgs = c.getDeclaredMethod(TESTMETHOD)
  2694                                     .getDeclaredAnnotationsByType(
  2695                                         srcType.getExpectedContainer(c).value());
  2696                         } catch (NoSuchMethodException nme) {
  2697                             error("Could not get " + TESTMETHOD
  2698                                     + " for className = " + c.getName()
  2699                                     + "Exception = " + nme);
  2701                         break;
  2702                     case FIELD:
  2703                         try {
  2704                             actualDeclAnnosArgs = c.getDeclaredField(TESTFIELD)
  2705                                    .getDeclaredAnnotationsByType(
  2706                                         srcType.getExpectedContainer(c).value());
  2707                         } catch (NoSuchFieldException nfe) {
  2708                             error("Could not get " + TESTFIELD
  2709                                     + " for className = " + c.getName()
  2710                                     + "Exception = " + nfe);
  2712                         break;
  2714                 return actualDeclAnnosArgs;
  2717             @Override
  2718             public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
  2719                 return srcType.getExpectedBase(c).getDeclAnnosArgs();
  2722             @Override
  2723             public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
  2724                 return srcType.getExpectedContainer(c).getDeclAnnosArgs();
  2726         }; // new
  2727         String name;
  2729         private TestMethod(String name) {
  2730             this.name = name;
  2733         public Annotation[] getActualAnnoBase(SrcType srcType, Class<?> c) {
  2734             return null;
  2737         public Annotation[] getActualAnnoContainer(SrcType srcType, Class<?> c) {
  2738             return null;
  2741         public String[] getExpectedAnnoBase(SrcType srcType, Class<?> c) {
  2742             return null;
  2745         public String[] getExpectedAnnoContainer(SrcType srcType, Class<?> c) {
  2746             return null;
  2750     /*
  2751      * For a given srcType and class object, compare expectedBase and actualBase
  2752      * annotations as well as expectedContainer and actualContainer annotations.
  2754      * Return true if both comparisons are true else return false.
  2756      */
  2757     protected static void checkAnnoValues(SrcType srcType, Class<?> c) {
  2759         // Load @ExpectedBase and @ExpectedContainer
  2760         ExpectedBase eb = srcType.getExpectedBase(c);
  2761         ExpectedContainer ec = srcType.getExpectedContainer(c);
  2762         if (eb == null) {
  2763             error("Did not find ExpectedBase Annotation, Test will exit");
  2764             throw new RuntimeException();
  2766         if (ec == null) {
  2767             error("Did not find ExpectedContainer Annotation, Test will exit");
  2768             throw new RuntimeException();
  2771         for (TestMethod testMethod : TestMethod.values()) {
  2772             debugPrint("---------------------------------------------");
  2773             debugPrint("Test method = " + testMethod);
  2774             boolean isBasePass = true;
  2775             boolean isConPass = true;
  2776             // ExpectedBase = Annotation, no annotation is defined, skip comparison
  2777             if (!eb.value().getSimpleName().equalsIgnoreCase("Annotation")) {
  2778                 isBasePass = compareAnnotations(
  2779                         testMethod.getActualAnnoBase(srcType, c),
  2780                         testMethod.getExpectedAnnoBase(srcType, c));
  2783             // ExpectedContainer = Annotation, no annotation is defined, skip comparison
  2784             if (!ec.value().getSimpleName().equalsIgnoreCase("Annotation")) {
  2785                 isConPass = compareAnnotations(
  2786                         testMethod.getActualAnnoContainer(srcType, c),
  2787                         testMethod.getExpectedAnnoContainer(srcType, c));
  2789             if (isBasePass && isConPass) {
  2790                 debugPrint("Testcase passed for " + testMethod +
  2791                         " for className = " + c.getName());
  2792             } else {
  2793                 debugPrint("Testcase failed for " + testMethod +
  2794                         " for className = " + c.getName());
  2799     // Annotation comparison: Length should be same and all expected values
  2800     // should be present in actualAnno[].
  2801     private static boolean compareAnnotations(Annotation[] actualAnnos,
  2802             String[] expectedAnnos) {
  2803         // Length is different
  2804         if (actualAnnos.length != expectedAnnos.length) {
  2805             error("Length not same, Actual length = " + actualAnnos.length
  2806                     + " Expected length = " + expectedAnnos.length);
  2807             printArrContents(actualAnnos);
  2808             printArrContents(expectedAnnos);
  2809             return false;
  2810         } else {
  2811             int i = 0;
  2812             // Length is same and 0
  2813             if (actualAnnos.length == 0) {
  2814                 // Expected/actual lengths already checked for
  2815                 // equality; no more checks do to
  2816                 return true;
  2818             // Expected annotation should be NULL
  2819             if (actualAnnos[0] == null) {
  2820                 if (expectedAnnos[0].equals("NULL")) {
  2821                     debugPrint("Arr values are NULL as expected");
  2822                     return true;
  2823                 } else {
  2824                     error("Array values are not NULL");
  2825                     printArrContents(actualAnnos);
  2826                     printArrContents(expectedAnnos);
  2827                     return false;
  2830             // Lengths are same, compare array contents
  2831             String[] actualArr = new String[actualAnnos.length];
  2832             for (Annotation a : actualAnnos) {
  2833                 actualArr[i++] = a.annotationType().getSimpleName();
  2836             List<String> actualList = Arrays.asList(actualArr);
  2837             List<String> expectedList = Arrays.asList(expectedAnnos);
  2839             if (!actualList.containsAll(expectedList)) {
  2840                 error("Array values are not same");
  2841                 printArrContents(actualAnnos);
  2842                 printArrContents(expectedAnnos);
  2843                 return false;
  2844             } else {
  2845                 debugPrint("Arr values are same as expected");
  2848         return true;
  2851     private static void printArrContents(Annotation[] actualAnnos) {
  2852         System.out.print("Actual Arr Values: ");
  2853         for (Annotation a : actualAnnos) {
  2854             if (a != null && a.annotationType() != null) {
  2855                 System.out.print("[" + a.annotationType().getSimpleName() + "]");
  2856             } else {
  2857                 System.out.println("[null]");
  2860         System.out.println();
  2863     private static void printArrContents(String[] expectedAnnos) {
  2864         System.out.print("Expected Arr Values: ");
  2865         for (String s : expectedAnnos) {
  2866             System.out.print("[" + s + "]");
  2868         System.out.println();
  2871     private ClassLoader getLoader() {
  2872         return getClass().getClassLoader();
  2875     private static Class<?> loadClass(String className, ClassLoader parentClassLoader, File... destDirs) {
  2876         try {
  2877             List<URL> list = new ArrayList<>();
  2878             for (File f : destDirs) {
  2879                 list.add(new URL("file:" + f.toString().replace("\\", "/") + "/"));
  2881             return Class.forName(className, true, new URLClassLoader(
  2882                     list.toArray(new URL[list.size()]), parentClassLoader));
  2883         } catch (ClassNotFoundException | MalformedURLException e) {
  2884             throw new RuntimeException("Error loading class " + className, e);
  2888     private static void printTestSrc(Iterable<? extends JavaFileObject> files) {
  2889         for (JavaFileObject f : files) {
  2890             System.out.println("Test file " + f.getName() + ":");
  2891             try {
  2892                 System.out.println("" + f.getCharContent(true));
  2893             } catch (IOException e) {
  2894                 throw new RuntimeException(
  2895                         "Exception when printing test src contents for class " +
  2896                                 f.getName(), e);
  2902     public static StringBuilder getCommonStmts(boolean isRepeatable) {
  2903         StringBuilder sb = new StringBuilder();
  2905         sb.append(Helper.ContentVars.IMPORTEXPECTED.getVal())
  2906           .append(Helper.ContentVars.IMPORTSTMTS.getVal())
  2907           .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
  2908           .append(Helper.ContentVars.INHERITED.getVal());
  2909         if(isRepeatable) {
  2910             sb.append(Helper.ContentVars.REPEATABLE.getVal());
  2912         sb.append(Helper.ContentVars.BASE.getVal())
  2913           .append(Helper.ContentVars.RETENTIONRUNTIME.getVal())
  2914           .append(Helper.ContentVars.INHERITED.getVal())
  2915           .append(Helper.ContentVars.CONTAINER.getVal());
  2916         return sb;
  2919     private static int getNumErrors() {
  2920         return errors;
  2923     private static void error(String msg) {
  2924         System.out.println("error: " + msg);
  2925         errors++;
  2928     private static void debugPrint(String string) {
  2929         if(DEBUG)
  2930             System.out.println(string);

mercurial