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 FinalizeShouldBeProtectedRuleTest extends SimpleAggregatorTst { 13 14 private Rule rule; 15 16 public void setUp() { 17 rule = new XPathRule(); 18 rule.addProperty("xpath", "//MethodDeclaration[@Protected=\"false\"]/MethodDeclarator[@Image=\"finalize\"][not(FormalParameters/*)]"); 19 } 20 21 public void testAll() { 22 runTests(new TestDescriptor[] { 23 new TestDescriptor(TEST1, "public finalize", 1, rule), 24 new TestDescriptor(TEST2, "finalize with some params", 0, rule), 25 new TestDescriptor(TEST3, "legitimate overriding", 0, rule) 26 }); 27 } 28 29 private static final String TEST1 = 30 "public class Foo {" + PMD.EOL + 31 " public void finalize() {}" + PMD.EOL + 32 "}"; 33 34 private static final String TEST2 = 35 "public class Foo {" + PMD.EOL + 36 " public void finalize(int x) {}" + PMD.EOL + 37 "}"; 38 39 private static final String TEST3 = 40 "public class Foo {" + PMD.EOL + 41 " protected void finalize() {}" + PMD.EOL + 42 "}"; 43 44 }

This page was automatically generated by Maven