1 /*** 2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html 3 */ 4 package test.net.sourceforge.pmd.rules.logging.java; 5 6 import net.sourceforge.pmd.PMD; 7 import net.sourceforge.pmd.Rule; 8 import net.sourceforge.pmd.RuleSetNotFoundException; 9 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; 10 import test.net.sourceforge.pmd.testframework.TestDescriptor; 11 12 public class LoggerIsNotStaticFinalTest extends SimpleAggregatorTst { 13 14 private Rule rule; 15 16 public void setUp() throws RuleSetNotFoundException { 17 rule = findRule("logging-java", "LoggerIsNotStaticFinal"); 18 } 19 20 public void testAll() { 21 runTests(new TestDescriptor[] { 22 new TestDescriptor(TEST1, "ok", 0, rule), 23 new TestDescriptor(TEST2, "two bad loggers", 2, rule), 24 new TestDescriptor(TEST3, "ok with internal class", 0, rule), 25 }); 26 } 27 28 private static final String TEST1 = 29 "public class Foo {" + PMD.EOL + 30 " static final Logger log;" + PMD.EOL + 31 "}"; 32 33 private static final String TEST2 = 34 "public class Foo {" + PMD.EOL + 35 " static final Logger log;" + PMD.EOL + 36 " Logger log1;" + PMD.EOL + 37 " Logger log2;" + PMD.EOL + 38 "}"; 39 40 private static final String TEST3 = 41 "public class Foo {" + PMD.EOL + 42 " static final Logger log;" + PMD.EOL + 43 " static class c { " + PMD.EOL + 44 " static final Logger log;" + PMD.EOL + 45 " } " + PMD.EOL + 46 "}"; 47 48 }