    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 test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    9   import test.net.sourceforge.pmd.testframework.TestDescriptor;
    10
    11  public class DuplicateImportsRuleTest extends SimpleAggregatorTst {
    12
    13      private Rule rule;
    14
    15      public void setUp() {
    16          rule = findRule("imports", "DuplicateImports");
    17      }
    18
    19      public void testAll() {
    20          runTests(new TestDescriptor[]{
    21              new TestDescriptor(TEST1, "duplicate single type imports", 1, rule),
    22              new TestDescriptor(TEST2, "duplicate wildcard imports", 1, rule),
    23              new TestDescriptor(TEST3, "single type import after wildcard import", 1, rule),
    24              new TestDescriptor(TEST4, "subpackage import, ok", 0, rule),
    25          });
    26      }
    27
    28      private static final String TEST1 =
    29              "import java.io.File;" + PMD.EOL +
    30              "import java.util.*;" + PMD.EOL +
    31              "import java.io.File;" + PMD.EOL +
    32              "public class Foo {}";
    33
    34      private static final String TEST2 =
    35              "import java.io.*;" + PMD.EOL +
    36              "import java.io.*;" + PMD.EOL +
    37              "public class Foo {}";
    38
    39      private static final String TEST3 =
    40              "import java.util.*;" + PMD.EOL +
    41              "import java.net.*;" + PMD.EOL +
    42              "import java.io.*;" + PMD.EOL +
    43              "import java.io.File;" + PMD.EOL +
    44              "public class Foo {}";
    45
    46      private static final String TEST4 =
    47              "import javax.servlet.*;" + PMD.EOL +
    48              "import javax.servlet.http.*;" + PMD.EOL +
    49              "public class Foo {}";
    50
    51  }