    1   package test.net.sourceforge.pmd.rules;
    2
    3   import net.sourceforge.pmd.PMD;
    4   import net.sourceforge.pmd.Rule;
    5   import net.sourceforge.pmd.RuleSetNotFoundException;
    6   import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
    7   import test.net.sourceforge.pmd.testframework.TestDescriptor;
    8
    9   public class UnnecessaryFinalModifierTest extends SimpleAggregatorTst {
    10      private Rule rule;
    11
    12      public void setUp() throws RuleSetNotFoundException {
    13          rule = findRule("basic", "UnnecessaryFinalModifier");
    14      }
    15
    16      public void testAll() {
    17          runTests(new TestDescriptor[]{
    18              new TestDescriptor(TEST1, "TEST1", 0, rule),
    19              new TestDescriptor(TEST2, "TEST2", 0, rule),
    20              new TestDescriptor(TEST3, "TEST3", 0, rule),
    21              new TestDescriptor(TEST4, "TEST4", 1, rule),
    22              new TestDescriptor(TEST5, "TEST5", 1, rule),
    23              new TestDescriptor(TEST6, "TEST6", 3, rule),
    24              new TestDescriptor(TEST7, "final method in inner class of non-final outer class", 0, rule),
    25              new TestDescriptor(TEST8, "final method in inner final class ", 1, rule),
    26          });
    27      }
    28
    29      private static final String TEST1 =
    30              "public class Foo {" + PMD.EOL +
    31              " public void foo() { }" + PMD.EOL +
    32              "}";
    33
    34      private static final String TEST2 =
    35              "public class Foo {" + PMD.EOL +
    36              " public final void foo() { }" + PMD.EOL +
    37              "}";
    38
    39      private static final String TEST3 =
    40              "public class Foo {" + PMD.EOL +
    41              " public final void foo() { }" + PMD.EOL +
    42              " public void foo2() { }" + PMD.EOL +
    43              "}";
    44
    45
    46      private static final String TEST4 =
    47              "public final class Foo {" + PMD.EOL +
    48              " public final void foo() { }" + PMD.EOL +
    49              "}";
    50
    51      private static final String TEST5 =
    52              "public final class Foo {" + PMD.EOL +
    53              " public final void foo() { }" + PMD.EOL +
    54              " public void foo2() { }" + PMD.EOL +
    55              "}";
    56
    57      private static final String TEST6 =
    58              "public final class Foo {" + PMD.EOL +
    59              " public final void fooA() { }" + PMD.EOL +
    60              " public final void fooS() { }" + PMD.EOL +
    61              " public final void fooD() { }" + PMD.EOL +
    62              " public void foo2() { }" + PMD.EOL +
    63              "}";
    64
    65      private static final String TEST7 =
    66              "public final class Foo {" + PMD.EOL +
    67              " public static class Bar {" + PMD.EOL +
    68              "  public final void buz() {}" + PMD.EOL +
    69              " }" + PMD.EOL +
    70              "}";
    71
    72      private static final String TEST8 =
    73              "public final class Foo {" + PMD.EOL +
    74              " public final class Bar {" + PMD.EOL +
    75              "  public final void buz() {}" + PMD.EOL +
    76              " }" + PMD.EOL +
    77              "}";
    78
    79  }