1 /***
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package test.net.sourceforge.pmd.rules.junit;
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.RuleTst;
10
11 public class JUnitSpellingRuleTest extends RuleTst {
12
13 private Rule rule;
14
15 public void setUp() {
16 rule = new XPathRule();
17 rule.addProperty("xpath", "//MethodDeclarator[(not(@Image = 'setUp') and translate(@Image, 'SETuP', 'setUp') = 'setUp') or (not(@Image = 'tearDown') and translate(@Image, 'TEARdOWN', 'tearDown') = 'tearDown')][FormalParameters[count(*) = 0]]");
18 }
19
20 public void testSetupMisspellings1() throws Throwable {
21 runTestFromString(TEST1, 2, rule);
22 }
23 public void testTeardownMisspellings() throws Throwable {
24 runTestFromString(TEST2, 2, rule);
25 }
26 public void testMethodsSpelledOK() throws Throwable {
27 runTestFromString(TEST3, 0, rule);
28 }
29 public void testUnrelatedMethods() throws Throwable {
30 runTestFromString(TEST4, 0, rule);
31 }
32 public void testMethodWithParams() throws Throwable {
33 runTestFromString(TEST5, 0, rule);
34 }
35
36 private static final String TEST1 =
37 "public class JUnitSpelling1 {" + PMD.EOL +
38 " // these should be 'setUp'" + PMD.EOL +
39 " public void setup() {}" + PMD.EOL +
40 " public void SetUp() {}" + PMD.EOL +
41 "}";
42
43 private static final String TEST2 =
44 "public class JUnitSpelling2 {" + PMD.EOL +
45 " // these should be 'tearDown'" + PMD.EOL +
46 " public void TearDown() {}" + PMD.EOL +
47 " public void teardown() {}" + PMD.EOL +
48 "}";
49
50 private static final String TEST3 =
51 "public class JUnitSpelling3 {" + PMD.EOL +
52 " // these are OK" + PMD.EOL +
53 " public void setUp() {}" + PMD.EOL +
54 " public void tearDown() {}" + PMD.EOL +
55 "}";
56
57 private static final String TEST4 =
58 "public class JUnitSpelling4 {" + PMD.EOL +
59 " // these are OK" + PMD.EOL +
60 " public void utility() {}" + PMD.EOL +
61 " public void foobr() {}" + PMD.EOL +
62 "}";
63
64 private static final String TEST5 =
65 "public class JUnitSpelling5 {" + PMD.EOL +
66 " public void setup(String x) {}" + PMD.EOL +
67 "}";
68
69 }
This page was automatically generated by Maven