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.RuleSetNotFoundException;
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() throws RuleSetNotFoundException {
16 rule = findRule("rulesets/junit.xml", "JUnitSpelling");
17 }
18
19 public void testSetupMisspellings1() throws Throwable {
20 runTestFromString(TEST1, 2, rule);
21 }
22 public void testTeardownMisspellings() throws Throwable {
23 runTestFromString(TEST2, 2, rule);
24 }
25 public void testMethodsSpelledOK() throws Throwable {
26 runTestFromString(TEST3, 0, rule);
27 }
28 public void testUnrelatedMethods() throws Throwable {
29 runTestFromString(TEST4, 0, rule);
30 }
31 public void testMethodWithParams() throws Throwable {
32 runTestFromString(TEST5, 0, rule);
33 }
34
35 private static final String TEST1 =
36 "public class JUnitSpelling1 {" + PMD.EOL +
37 " // these should be 'setUp'" + PMD.EOL +
38 " public void setup() {}" + PMD.EOL +
39 " public void SetUp() {}" + PMD.EOL +
40 "}";
41
42 private static final String TEST2 =
43 "public class JUnitSpelling2 {" + PMD.EOL +
44 " // these should be 'tearDown'" + PMD.EOL +
45 " public void TearDown() {}" + PMD.EOL +
46 " public void teardown() {}" + PMD.EOL +
47 "}";
48
49 private static final String TEST3 =
50 "public class JUnitSpelling3 {" + PMD.EOL +
51 " // these are OK" + PMD.EOL +
52 " public void setUp() {}" + PMD.EOL +
53 " public void tearDown() {}" + PMD.EOL +
54 "}";
55
56 private static final String TEST4 =
57 "public class JUnitSpelling4 {" + PMD.EOL +
58 " // these are OK" + PMD.EOL +
59 " public void utility() {}" + PMD.EOL +
60 " public void foobr() {}" + PMD.EOL +
61 "}";
62
63 private static final String TEST5 =
64 "public class JUnitSpelling5 {" + PMD.EOL +
65 " public void setup(String x) {}" + PMD.EOL +
66 "}";
67 }