1   /***
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package test.net.sourceforge.pmd.rules.design;
5   
6   import net.sourceforge.pmd.PMD;
7   import net.sourceforge.pmd.Rule;
8   import net.sourceforge.pmd.RuleSetNotFoundException;
9   import net.sourceforge.pmd.rules.design.LongClassRule;
10  import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
11  import test.net.sourceforge.pmd.testframework.TestDescriptor;
12  
13  public class LongClassRuleTest extends SimpleAggregatorTst {
14  
15      private Rule rule;
16  
17      public void setUp() throws RuleSetNotFoundException {
18          rule = findRule("codesize", "ExcessiveClassLength");
19          rule.addProperty("minimum", "10");
20      }
21  
22      public void testAll() {
23          runTests(new TestDescriptor[]{
24              new TestDescriptor(TEST0, "short", 0, rule),
25              new TestDescriptor(TEST1, "long", 1, rule),
26          });
27      }
28  
29      public void testLongClassWithLongerTest() throws Throwable {
30          LongClassRule IUT = new LongClassRule();
31          IUT.addProperty("minimum", "2000");
32          runTestFromString(TEST1, 0, IUT);
33      }
34  
35      private static final String TEST0 =
36              "public class Foo {" + PMD.EOL +
37              "    public static void main(String args[]) {" + PMD.EOL +
38              "	  int x;" + PMD.EOL +
39              "    }" + PMD.EOL +
40              "}";
41  
42      private static final String TEST1 =
43              "public class Foo {" + PMD.EOL +
44              "    public void bar() {" + PMD.EOL +
45              "	  bar();" + PMD.EOL +
46              "	  bar();" + PMD.EOL +
47              "	  bar();" + PMD.EOL +
48              "	  bar();" + PMD.EOL +
49              "	  bar();" + PMD.EOL +
50              "	  bar();" + PMD.EOL +
51              "	  bar();" + PMD.EOL +
52              "	  bar();" + PMD.EOL +
53              "	  bar();" + PMD.EOL +
54              "	  bar();" + PMD.EOL +
55              "    }" + PMD.EOL +
56              "}";
57  }
58