1 package test.net.sourceforge.pmd.rules;
2
3 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
4 import test.net.sourceforge.pmd.testframework.TestDescriptor;
5 import net.sourceforge.pmd.Rule;
6 import net.sourceforge.pmd.PMD;
7 import net.sourceforge.pmd.rules.XPathRule;
8
9 public class SuspiciousHashcodeMethodNameRuleTest extends SimpleAggregatorTst {
10 private Rule rule;
11
12 public void setUp() {
13 rule = new XPathRule();
14 rule.addProperty("xpath", "//MethodDeclaration[ResultType//PrimitiveType[@Image='int'][//MethodDeclarator[@Image='hashcode' or @Image='HashCode' or @Image='Hashcode'][not(FormalParameters/*)]");
15 }
16
17 public void testAll() {
18 runTests(new TestDescriptor[] {
19 new TestDescriptor(TEST1, "ok", 0, rule),
20 new TestDescriptor(TEST2, "hashcode", 1, rule),
21 new TestDescriptor(TEST3, "HashCode", 1, rule),
22 new TestDescriptor(TEST4, "Hashcode", 1, rule),
23 });
24 }
25
26 private static final String TEST1 =
27 "public class Foo {" + PMD.EOL +
28 " public int hashCode() {return 42;}" + PMD.EOL +
29 "}";
30
31 private static final String TEST2 =
32 "public class Foo {" + PMD.EOL +
33 " public int hashcode() {return 42;}" + PMD.EOL +
34 "}";
35
36 private static final String TEST3 =
37 "public class Foo {" + PMD.EOL +
38 " public int HashCode() {return 42;}" + PMD.EOL +
39 "}";
40
41 private static final String TEST4 =
42 "public class Foo {" + PMD.EOL +
43 " public int Hashcode() {return 42;}" + PMD.EOL +
44 "}";
45
46 }
This page was automatically generated by Maven