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.rules.XPathRule;
9 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
10 import test.net.sourceforge.pmd.testframework.TestDescriptor;
11
12 public class ShortMethodNameRuleTest extends SimpleAggregatorTst {
13
14 private Rule rule;
15
16 public void setUp() {
17 rule = new XPathRule();
18 rule.addProperty("xpath", "//MethodDeclarator[string-length(@Image) < 3]");
19 }
20
21 public void testAll() {
22 runTests(new TestDescriptor[] {
23 new TestDescriptor(TEST1, "ok", 0, rule),
24 new TestDescriptor(TEST2, "bad", 1, rule),
25 new TestDescriptor(TEST3, "2 violations", 2, rule),
26 new TestDescriptor(TEST4, "2 methods, 1 violation", 1, rule),
27 });
28 }
29
30 private static final String TEST1 =
31 "public class ShortMethodName0 {" + PMD.EOL +
32 " public int abcd( int i ) {" + PMD.EOL +
33 " // Should not violate." + PMD.EOL +
34 " }" + PMD.EOL +
35 "}";
36
37 private static final String TEST2 =
38 "public class ShortMethodName1 {" + PMD.EOL +
39 " public int a( int i ) {" + PMD.EOL +
40 " // Should violate." + PMD.EOL +
41 " }" + PMD.EOL +
42 "}";
43
44 private static final String TEST3 =
45 "public class ShortMethodName2 {" + PMD.EOL +
46 " public int a( int i ) {" + PMD.EOL +
47 " // Should violate" + PMD.EOL +
48 " }" + PMD.EOL +
49 "" + PMD.EOL +
50 " public int b( int i ) {" + PMD.EOL +
51 " // Should violate" + PMD.EOL +
52 " }" + PMD.EOL +
53 "}";
54
55 private static final String TEST4 =
56 "public class ShortMethodName3 {" + PMD.EOL +
57 " public int a( int i ) {" + PMD.EOL +
58 " // Should violate" + PMD.EOL +
59 " }" + PMD.EOL +
60 "" + PMD.EOL +
61 " public int bcde( int i ) {" + PMD.EOL +
62 " // Should not violate" + PMD.EOL +
63 " }" + PMD.EOL +
64 "}";
65
66 }
This page was automatically generated by Maven