View Javadoc
1 package test.net.sourceforge.pmd.rules.finalize; 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 FinalizeOnlyCallsSuperFinalizeRuleTest extends SimpleAggregatorTst { 10 11 private Rule rule; 12 13 public void setUp() { 14 rule = new XPathRule(); 15 rule.addProperty("xpath", "//MethodDeclaration[MethodDeclarator[@Image='finalize'][not(FormalParameters/*)]]/Block[count(BlockStatement)=1]/BlockStatement[Statement/StatementExpression/PrimaryExpression/PrimaryPrefix[@Image='finalize']"); 16 } 17 18 public void testAll() { 19 runTests(new TestDescriptor[] { 20 new TestDescriptor(TEST1, "bad", 1, rule), 21 new TestDescriptor(TEST2, "ok", 0, rule), 22 }); 23 } 24 25 private static final String TEST1 = 26 "public class Foo {" + PMD.EOL + 27 " public void finalize() {" + PMD.EOL + 28 " super.finalize();" + PMD.EOL + 29 " }" + PMD.EOL + 30 "}"; 31 32 private static final String TEST2 = 33 "public class Foo {" + PMD.EOL + 34 " public void finalize() {" + PMD.EOL + 35 " int x = 2;" + PMD.EOL + 36 " super.finalize();" + PMD.EOL + 37 " }" + PMD.EOL + 38 "}"; 39 }

This page was automatically generated by Maven