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.rules.UnusedImportsRule; 8 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; 9 import test.net.sourceforge.pmd.testframework.TestDescriptor; 10 11 public class UnusedImportsRuleTest extends SimpleAggregatorTst { 12 13 private UnusedImportsRule rule; 14 15 public void setUp() { 16 rule = new UnusedImportsRule(); 17 rule.setMessage("Avoid this stuff -> ''{0}''"); 18 } 19 20 public void testAll() { 21 runTests(new TestDescriptor[] { 22 new TestDescriptor(TEST1, "simple unused single type import", 1, rule), 23 new TestDescriptor(TEST2, "one used single type import", 0, rule), 24 new TestDescriptor(TEST3, "2 unused single-type imports", 2, rule), 25 new TestDescriptor(TEST4, "1 used single type import", 0, rule) 26 }); 27 } 28 29 private static final String TEST1 = 30 "import java.io.File;" + PMD.EOL + 31 "public class UnusedImports1 {}"; 32 33 private static final String TEST2 = 34 "import java.io.File;" + PMD.EOL + 35 "public class UnusedImports2 {" + PMD.EOL + 36 " private File file;" + PMD.EOL + 37 "}"; 38 39 private static final String TEST3 = 40 "import java.io.File;" + PMD.EOL + 41 "import java.util.List;" + PMD.EOL + 42 "public class UnusedImports3 {" + PMD.EOL + 43 "}"; 44 45 private static final String TEST4 = 46 "import java.security.AccessController;" + PMD.EOL + 47 "public class UnusedImports4 {" + PMD.EOL + 48 " public void foo() {" + PMD.EOL + 49 " AccessController.doPrivileged(null);" + PMD.EOL + 50 " }" + PMD.EOL + 51 "}"; 52 53 54 }

This page was automatically generated by Maven