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.AccessorClassGenerationRule; 8 import test.net.sourceforge.pmd.testframework.RuleTst; 9 10 public class AccessorClassGenerationRuleTest extends RuleTst { 11 12 public void testInnerClassHasPrivateConstructor() throws Throwable { 13 runTestFromString(TEST1, 1, new AccessorClassGenerationRule()); 14 } 15 16 public void testInnerClassHasPublicConstructor() throws Throwable { 17 runTestFromString(TEST2, 0, new AccessorClassGenerationRule()); 18 } 19 20 public void testOuterClassHasPrivateConstructor() throws Throwable { 21 runTestFromString(TEST3, 1, new AccessorClassGenerationRule()); 22 } 23 24 public void testFinalInnerClass() throws Throwable { 25 runTestFromString(TEST4, 0, new AccessorClassGenerationRule()); 26 } 27 28 private static final String TEST1 = 29 "public class Foo1 {" + PMD.EOL + 30 " public class InnerClass {" + PMD.EOL + 31 " private InnerClass(){" + PMD.EOL + 32 " }" + PMD.EOL + 33 " }" + PMD.EOL + 34 " void method(){" + PMD.EOL + 35 " new InnerClass();//Causes generation of accessor" + PMD.EOL + 36 " }" + PMD.EOL + 37 "}"; 38 39 private static final String TEST2 = 40 "public class Foo2 {" + PMD.EOL + 41 " public class InnerClass {" + PMD.EOL + 42 " public InnerClass(){" + PMD.EOL + 43 " }" + PMD.EOL + 44 " }" + PMD.EOL + 45 " void method(){" + PMD.EOL + 46 " new InnerClass(); //OK, due to public constructor" + PMD.EOL + 47 " }" + PMD.EOL + 48 "}"; 49 50 private static final String TEST3 = 51 "public class Foo3 {" + PMD.EOL + 52 " public class InnerClass {" + PMD.EOL + 53 " void method(){" + PMD.EOL + 54 " new Foo3();//Causes generation of accessor" + PMD.EOL + 55 " }" + PMD.EOL + 56 " }" + PMD.EOL + 57 " private Foo3() {" + PMD.EOL + 58 " }" + PMD.EOL + 59 "}"; 60 61 private static final String TEST4 = 62 "public class Foo {" + PMD.EOL + 63 " void method() {" + PMD.EOL + 64 " final class Inner {}; " + PMD.EOL + 65 " Inner i = new Inner();" + PMD.EOL + 66 " }" + PMD.EOL + 67 "}"; 68 }