1 /* $Id: LongMethodRuleTest.java,v 1.11 2003/06/26 21:13:13 tomcopeland Exp $ */
2
3 package test.net.sourceforge.pmd.rules.design;
4
5 import net.sourceforge.pmd.PMD;
6 import net.sourceforge.pmd.rules.design.LongMethodRule;
7 import test.net.sourceforge.pmd.rules.RuleTst;
8
9 public class LongMethodRuleTest extends RuleTst {
10
11 private LongMethodRule getIUT() {
12 LongMethodRule IUT = new LongMethodRule();
13 IUT.addProperty("minimum", "10");
14 return IUT;
15 }
16
17 public void testShortMethod() throws Throwable {
18 runTestFromString(TEST1, 0, getIUT());
19 }
20 public void testReallyLongMethod() throws Throwable {
21 runTestFromString(TEST2, 1, getIUT());
22 }
23 public void testReallyLongMethodWithLongerRange() throws Throwable {
24 LongMethodRule IUT = getIUT();
25 IUT.addProperty("minimum", "20");
26 runTestFromString(TEST2, 0, IUT);
27 }
28 public void testNotQuiteLongMethod() throws Throwable {
29 runTestFromString(TEST3, 0, getIUT());
30 }
31 public void testLongMethod() throws Throwable {
32 runTestFromString(TEST4, 1, getIUT());
33 }
34
35 private static final String TEST1 =
36 "public class LongMethod1 {" + PMD.EOL +
37 " public static void main(String args[]) {" + PMD.EOL +
38 " System.err.println(\"This is short.\");" + PMD.EOL +
39 " }" + PMD.EOL +
40 "}";
41
42 private static final String TEST2 =
43 "public class LongMethod2 {" + PMD.EOL +
44 " public static void main(String args[]) {" + PMD.EOL +
45 " System.err.println(\"This is long.\");" + PMD.EOL +
46 " System.err.println(\"This is long.\");" + PMD.EOL +
47 " System.err.println(\"This is long.\");" + PMD.EOL +
48 " System.err.println(\"This is long.\");" + PMD.EOL +
49 " System.err.println(\"This is long.\");" + PMD.EOL +
50 " System.err.println(\"This is long.\");" + PMD.EOL +
51 " System.err.println(\"This is long.\");" + PMD.EOL +
52 " System.err.println(\"This is long.\");" + PMD.EOL +
53 " System.err.println(\"This is long.\");" + PMD.EOL +
54 " System.err.println(\"This is long.\");" + PMD.EOL +
55 " System.err.println(\"This is long.\");" + PMD.EOL +
56 " System.err.println(\"This is long.\");" + PMD.EOL +
57 " } // 11 lines - violation" + PMD.EOL +
58 "}";
59
60 private static final String TEST3 =
61 "public class LongMethod2 {" + PMD.EOL +
62 " public static void main(String args[]) {" + PMD.EOL +
63 " System.err.println(\"This is long, but not a violation\");" + PMD.EOL +
64 " System.err.println(\"This is long, but not a violation\");" + PMD.EOL +
65 " System.err.println(\"This is long, but not a violation\");" + PMD.EOL +
66 " System.err.println(\"This is long, but not a violation\");" + PMD.EOL +
67 " System.err.println(\"This is long, but not a violation\");" + PMD.EOL +
68 " System.err.println(\"This is long, but not a violation\");" + PMD.EOL +
69 " System.err.println(\"This is long, but not a violation\");" + PMD.EOL +
70 " System.err.println(\"This is long, but not a violation\");" + PMD.EOL +
71 " } // 9 lines - Not a violation" + PMD.EOL +
72 "}";
73
74 private static final String TEST4 =
75 "public class LongMethod2 {" + PMD.EOL +
76 " public static void main(String args[]) {" + PMD.EOL +
77 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
78 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
79 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
80 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
81 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
82 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
83 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
84 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
85 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
86 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
87 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
88 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
89 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
90 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
91 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
92 " System.err.println(\"This is long, and is a violation\");" + PMD.EOL +
93 " } // > 10 lines - Not a violation" + PMD.EOL +
94 "}";
95 }
96
This page was automatically generated by Maven