    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 AvoidFieldNameMatchingMethodNameTest extends SimpleAggregatorTst {
    13
    14      private Rule rule;
    15
    16      public void setUp() throws RuleSetNotFoundException {
    17          rule = findRule("naming", "AvoidFieldNameMatchingMethodName");
    18      }
    19
    20      public void testAll() {
    21          runTests(new TestDescriptor[]{
    22              new TestDescriptor(TEST1, "TEST1", 1, rule),
    23              new TestDescriptor(TEST2, "TEST2", 1, rule),
    24              new TestDescriptor(TEST3, "TEST3", 0, rule),
    25              new TestDescriptor(TEST4, "TEST4", 0, rule),
    26              new TestDescriptor(TEST5, "Just skip interfaces", 0, rule),
    27          });
    28      }
    29
    30      private static final String TEST1 =
    31              "public class Foo {" + PMD.EOL +
    32              "   int bar;" + PMD.EOL +
    33              "   void bar() {}" + PMD.EOL +
    34              "} ";
    35
    36      private static final String TEST2 =
    37              "public class Bar {" + PMD.EOL +
    38              "   class Dummy {" + PMD.EOL +
    39              "		Foo foo;" + PMD.EOL +
    40              "		void foo() {}" + PMD.EOL +
    41              "   }" + PMD.EOL +
    42              "} ";
    43
    44      private static final String TEST3 =
    45              "public class Bar {" + PMD.EOL +
    46              "   Foo foo;" + PMD.EOL +
    47              "   class Dummy {" + PMD.EOL +
    48              "		void foo() {}" + PMD.EOL +
    49              "   }" + PMD.EOL +
    50              "} ";
    51
    52      private static final String TEST4 =
    53              "public class Bar {" + PMD.EOL +
    54              "	void foo() {}" + PMD.EOL +
    55              "   class Dummy {" + PMD.EOL +
    56              "      Foo foo;" + PMD.EOL +
    57              "   }" + PMD.EOL +
    58              "} ";
    59
    60      private static final String TEST5 =
    61              "public interface Bar {" + PMD.EOL +
    62              "  public static final int FOO = 5;" + PMD.EOL +
    63              "} ";
    64
    65  }
    66