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 DontImportJavaLangRuleTest extends SimpleAggregatorTst { 13 14 private Rule rule; 15 16 public void setUp() { 17 rule = new XPathRule(); 18 rule.addProperty("xpath", "//ImportDeclaration" 19 + "[starts-with(Name/@Image, 'java.lang')]" 20 + "[not(starts-with(Name/@Image, 'java.lang.ref'))]" 21 + "[not(starts-with(Name/@Image, 'java.lang.reflect'))]"); 22 } 23 24 public void testAll() { 25 runTests(new TestDescriptor[] { 26 new TestDescriptor(TEST1, "", 1, rule), 27 new TestDescriptor(TEST2, "", 1, rule), 28 new TestDescriptor(TEST3, "", 0, rule), 29 }); 30 } 31 32 private static final String TEST1 = 33 "import java.lang.String;" + PMD.EOL + 34 "public class DontImportJavaLang1 {}"; 35 36 private static final String TEST2 = 37 "import java.lang.*;" + PMD.EOL + 38 "public class DontImportJavaLang2 {}"; 39 40 private static final String TEST3 = 41 "import java.lang.ref.*;" + PMD.EOL + 42 "import java.lang.reflect.*;" + PMD.EOL + 43 "public class DontImportJavaLang3 {}"; 44 45 }

This page was automatically generated by Maven