View Javadoc
1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 package test.net.sourceforge.pmd.rules; 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.SimpleAggregatorTst; 10 import test.net.sourceforge.pmd.testframework.TestDescriptor; 11 12 public class BooleanInstantiationRuleTest extends SimpleAggregatorTst { 13 14 private Rule rule; 15 16 public void setUp() { 17 rule = new XPathRule(); 18 rule.addProperty( 19 "xpath", 20 "//AllocationExpression[not (ArrayDimsAndInits) and (Name/@Image='Boolean' or Name/@Image='java.lang.Boolean')]"); 21 } 22 23 public void testAll() { 24 runTests(new TestDescriptor[] { 25 new TestDescriptor(TEST1, "simple failure case", 1, rule), 26 new TestDescriptor(TEST2, "new java.lang.Boolean", 1, rule), 27 new TestDescriptor(TEST3, "ok", 0, rule), 28 }); 29 } 30 31 private static final String TEST1 = 32 "public class Foo {" + PMD.EOL + 33 " Boolean b = new Boolean(\"true\");" + PMD.EOL + 34 "}"; 35 36 private static final String TEST2 = 37 "public class Foo {" + PMD.EOL + 38 " Boolean b = new java.lang.Boolean(\"true\");" + PMD.EOL + 39 "}"; 40 41 private static final String TEST3 = 42 "public class Foo {" + PMD.EOL + 43 " Boolean b = Boolean.TRUE;" + PMD.EOL + 44 "}"; 45 46 }

This page was automatically generated by Maven