View Javadoc
1 package test.net.sourceforge.pmd.rules; 2 3 import net.sourceforge.pmd.PMD; 4 import net.sourceforge.pmd.Rule; 5 import net.sourceforge.pmd.rules.XPathRule; 6 7 public class FinalizeShouldBeProtectedRuleTest extends SimpleAggregatorTst { 8 9 private Rule rule; 10 11 public void setUp() { 12 rule = new XPathRule(); 13 rule.addProperty("xpath", "//MethodDeclaration[@Protected=\"false\"]/MethodDeclarator[@Image=\"finalize\"][not(FormalParameters/*)]"); 14 } 15 16 public void testAll() { 17 runTests(new TestDescriptor[] { 18 new TestDescriptor(TEST1, "public finalize", 1, rule), 19 new TestDescriptor(TEST2, "finalize with some params", 0, rule), 20 new TestDescriptor(TEST3, "legitimate overriding", 0, rule) 21 }); 22 } 23 24 private static final String TEST1 = 25 "public class Foo {" + PMD.EOL + 26 " public void finalize() {}" + PMD.EOL + 27 "}"; 28 29 private static final String TEST2 = 30 "public class Foo {" + PMD.EOL + 31 " public void finalize(int x) {}" + PMD.EOL + 32 "}"; 33 34 private static final String TEST3 = 35 "public class Foo {" + PMD.EOL + 36 " protected void finalize() {}" + PMD.EOL + 37 "}"; 38 39 }

This page was automatically generated by Maven