    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package test.net.sourceforge.pmd.rules.imports;
    5
    6   import net.sourceforge.pmd.PMD;
    7   import net.sourceforge.pmd.Rule;
    8   import net.sourceforge.pmd.RuleSetNotFoundException;
    9   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    10  import test.net.sourceforge.pmd.testframework.TestDescriptor;
    11
    12  public class DontImportJavaLangRuleTest extends SimpleAggregatorTst {
    13
    14      private Rule rule;
    15
    16      public void setUp() throws RuleSetNotFoundException {
    17          rule = findRule("imports", "DontImportJavaLang");
    18      }
    19
    20      public void testAll() {
    21          runTests(new TestDescriptor[]{
    22              new TestDescriptor(TEST1, "import java.lang.String", 1, rule),
    23              new TestDescriptor(TEST2, "import java.lang.*", 1, rule),
    24              new TestDescriptor(TEST3, "import java.lang.ref/reflect/annotation/instrument/management", 0, rule),
    25          });
    26      }
    27
    28      private static final String TEST1 =
    29              "import java.lang.String;" + PMD.EOL +
    30              "public class Foo {}";
    31
    32      private static final String TEST2 =
    33              "import java.lang.*;" + PMD.EOL +
    34              "public class Foo {}";
    35
    36      private static final String TEST3 =
    37              "import java.lang.ref.*;" + PMD.EOL +
    38              "import java.lang.reflect.*;" + PMD.EOL +
    39              "import java.lang.annotation.*;" + PMD.EOL +
    40              "import java.lang.instrument.*;" + PMD.EOL +
    41              "import java.lang.management.*;" + PMD.EOL +
    42              "public class Foo {}";
    43
    44  }