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 LongVariableRuleTest extends SimpleAggregatorTst {
13  
14      private Rule rule;
15  
16      public void setUp() throws RuleSetNotFoundException {
17          rule = findRule("naming", "LongVariable");
18      }
19  
20      public void testAll() {
21          runTests(new TestDescriptor[]{
22              new TestDescriptor(TEST1, "param", 1, rule),
23              new TestDescriptor(TEST2, "ok", 0, rule),
24              new TestDescriptor(TEST3, "local", 1, rule),
25              new TestDescriptor(TEST4, "for", 1, rule),
26              new TestDescriptor(TEST5, "17 character max", 1, rule),
27          });
28      }
29  
30      public void testThreshold() {
31          rule.addProperty("minimum", "3");
32          runTests(new TestDescriptor[]{
33              new TestDescriptor(TEST6, "threshold test", 2, rule),
34          });
35  
36      }
37  
38      private static final String TEST1 =
39              "public class Foo {" + PMD.EOL +
40              "    void foo(String argsWithExtraMustard) {} " + PMD.EOL +
41              "}";
42  
43      private static final String TEST2 =
44              "public class Foo {" + PMD.EOL +
45              "    void foo() {" + PMD.EOL +
46              "       int bugleDeWump = -1;" + PMD.EOL +
47              "    }" + PMD.EOL +
48              "}";
49  
50      private static final String TEST3 =
51              "public class Foo {" + PMD.EOL +
52              "" + PMD.EOL +
53              "    void foo() {" + PMD.EOL +
54              "       int abcdefghijklmnopqrstuvwxyz = -1; " + PMD.EOL +
55              "    }" + PMD.EOL +
56              "}";
57  
58      private static final String TEST4 =
59              "public class Foo {" + PMD.EOL +
60              "   void foo() {" + PMD.EOL +
61              "       for (int interestingIntIterator = 0; " + PMD.EOL +
62              "            interestingIntIterator < 10; " + PMD.EOL +
63              "            interestingIntIterator++) { }" + PMD.EOL +
64              "    }" + PMD.EOL +
65              "}";
66  
67      private static final String TEST5 =
68              "public class Foo {" + PMD.EOL +
69              "    private int a2345678901234567;" + PMD.EOL +
70              "    private int a23456789012345678;" + PMD.EOL +
71              "}";
72  
73      private static final String TEST6 =
74              "public class Foo {" + PMD.EOL +
75              "    private int a234;" + PMD.EOL +
76              "    private int b234;" + PMD.EOL +
77              "}";
78  
79  }