    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 AvoidFieldNameMatchingTypeNameTest extends SimpleAggregatorTst {
    13
    14      private Rule rule;
    15
    16      public void setUp() throws RuleSetNotFoundException {
    17          rule = findRule("naming", "AvoidFieldNameMatchingTypeName");
    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", 1, rule),
    26          });
    27      }
    28
    29      private static final String TEST1 =
    30              "public class Foo {" + PMD.EOL +
    31              "   int foo;" + PMD.EOL +
    32              "} ";
    33
    34      private static final String TEST2 =
    35              "public class Foo {" + PMD.EOL +
    36              "   String foo;" + PMD.EOL +
    37              "} ";
    38
    39      private static final String TEST3 =
    40              "public class Foo {" + PMD.EOL +
    41              "   class Bar {" + PMD.EOL +
    42              "		Foo foo;" + PMD.EOL +
    43              "   }" + PMD.EOL +
    44              "} ";
    45
    46      private static final String TEST4 =
    47              "public class Foo {" + PMD.EOL +
    48              "   class Bar {" + PMD.EOL +
    49              "		String bar;" + PMD.EOL +
    50              "   }" + PMD.EOL +
    51              "} ";
    52  }