    1   /***
    2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
    3    */
    4   package test.net.sourceforge.pmd.rules;
    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 AtLeastOneConstructorRuleTest extends SimpleAggregatorTst {
    13
    14      private Rule rule;
    15
    16      public void setUp() throws RuleSetNotFoundException {
    17          rule = findRule("controversial", "AtLeastOneConstructor");
    18      }
    19
    20      public void testAll() {
    21          runTests(new TestDescriptor[]{
    22              new TestDescriptor(TEST1, "ok", 0, rule),
    23              new TestDescriptor(TEST2, "simple failure case", 1, rule),
    24              new TestDescriptor(TEST3, "inner bad, outer ok", 1, rule),
    25              new TestDescriptor(TEST4, "inner ok, outer bad", 1, rule),
    26              new TestDescriptor(TEST5, "inner and outer both bad", 2, rule),
    27              new TestDescriptor(TEST6, "inner and outer both ok", 0, rule),
    28              new TestDescriptor(TEST7, "skip interfaces", 0, rule),
    29          });
    30      }
    31
    32      private static final String TEST1 =
    33              "public class Foo {" + PMD.EOL +
    34              " public Foo() {}" + PMD.EOL +
    35              "}";
    36
    37      private static final String TEST2 =
    38              "public class Foo {}";
    39
    40      private static final String TEST3 =
    41              "public class Foo {" + PMD.EOL +
    42              " public class Bar {}" + PMD.EOL +
    43              " public Foo() {}" + PMD.EOL +
    44              "}";
    45
    46      private static final String TEST4 =
    47              "public class Foo {" + PMD.EOL +
    48              " public class Bar { " + PMD.EOL +
    49              "  public Bar() {}" + PMD.EOL +
    50              " }" + PMD.EOL +
    51              "}";
    52
    53      private static final String TEST5 =
    54              "public class Foo {" + PMD.EOL +
    55              " public class Bar {} " + PMD.EOL +
    56              "}";
    57
    58      private static final String TEST6 =
    59              "public class Foo {" + PMD.EOL +
    60              " public class Bar { " + PMD.EOL +
    61              "  public Bar() {}" + PMD.EOL +
    62              " }" + PMD.EOL +
    63              " public Foo() {}" + PMD.EOL +
    64              "}";
    65
    66      private static final String TEST7 =
    67              "public interface Foo {" + PMD.EOL +
    68              "}";
    69
    70  }