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