1 package test.net.sourceforge.pmd.rules;
2
3 import net.sourceforge.pmd.Rule;
4 import net.sourceforge.pmd.RuleSetNotFoundException;
5 import net.sourceforge.pmd.PMD;
6 import test.net.sourceforge.pmd.testframework.TestDescriptor;
7 import test.net.sourceforge.pmd.testframework.RuleTst;
8 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
9
10 public class BadComparisonRuleTest extends SimpleAggregatorTst {
11
12 private Rule rule;
13
14 public void setUp() throws RuleSetNotFoundException {
15 rule = findRule("rulesets/design.xml", "BadComparisonRule");
16 }
17
18 public void testAll() {
19 runTests(new TestDescriptor[] {
20 new TestDescriptor(TEST1, "comparison to Double.NaN", 1, rule),
21 new TestDescriptor(TEST2, "ok equality comparison", 0, rule),
22 new TestDescriptor(TEST3, "comparison to Float.NaN", 1, rule),
23 });
24 }
25
26 private static final String TEST1 =
27 "public class Foo {" + PMD.EOL +
28 " boolean x = (y == Double.NaN);" + PMD.EOL +
29 "}";
30
31 private static final String TEST2 =
32 "public class Foo {" + PMD.EOL +
33 " boolean x = (y == z);" + PMD.EOL +
34 "}";
35
36 private static final String TEST3 =
37 "public class Foo {" + PMD.EOL +
38 " boolean x = (y == Float.NaN);" + PMD.EOL +
39 "}";
40
41 }