    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 ImportFromSamePackageRuleTest extends SimpleAggregatorTst {
    13
    14      private Rule rule;
    15
    16      public void setUp() throws RuleSetNotFoundException {
    17          rule = findRule("imports", "ImportFromSamePackage");
    18      }
    19
    20      public void testAll() {
    21          runTests(new TestDescriptor[]{
    22              new TestDescriptor(TEST1, "simple failure", 1, rule),
    23              new TestDescriptor(TEST2, "class in default package importing from sub package", 0, rule),
    24              new TestDescriptor(TEST3, "class in default package importing from other package", 0, rule),
    25              new TestDescriptor(TEST4, "class not in default package importing from default package", 0, rule),
    26              new TestDescriptor(TEST5, "class in default package importing from default package", 1, rule),
    27              new TestDescriptor(TEST6, "importing from subpackage", 0, rule),
    28              new TestDescriptor(TEST7, "importing all from same package", 1, rule),
    29          });
    30      }
    31
    32      private static final String TEST1 =
    33              "package foo;" + PMD.EOL +
    34              "import foo.Bar;" + PMD.EOL +
    35              "public class Baz{}";
    36
    37      private static final String TEST2 =
    38              "package foo;" + PMD.EOL +
    39              "import foo.buz.Bar;" + PMD.EOL +
    40              "public class Baz{}";
    41
    42      private static final String TEST3 =
    43              "import java.util.*;" + PMD.EOL +
    44              "public class Baz{}";
    45
    46      private static final String TEST4 =
    47              "package bar;" + PMD.EOL +
    48              "import Foo;" + PMD.EOL +
    49              "public class Baz{}";
    50
    51      private static final String TEST5 =
    52              "import Foo;" + PMD.EOL +
    53              "public class Baz{}";
    54
    55      private static final String TEST6 =
    56              "package foo.bar;" + PMD.EOL +
    57              "import foo.bar.baz.*;" + PMD.EOL +
    58              "public class Baz{}";
    59
    60      private static final String TEST7 =
    61              "package foo.bar;" + PMD.EOL +
    62              "import foo.bar.*;" + PMD.EOL +
    63              "public class Baz{}";
    64
    65  }