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.RuleSetNotFoundException; 9 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; 10 import test.net.sourceforge.pmd.testframework.TestDescriptor; 11 12 public class UnusedModifierRuleTest extends SimpleAggregatorTst { 13 14 private Rule rule; 15 16 public void setUp() throws RuleSetNotFoundException { 17 rule = findRule("rulesets/controversial.xml", "UnusedModifier"); 18 } 19 20 public void testAll() { 21 runTests(new TestDescriptor[] { 22 new TestDescriptor(TEST1, "wasted 'public' in interface method", 1, rule), 23 new TestDescriptor(TEST2, "class, no problem", 0, rule), 24 new TestDescriptor(TEST3, "wasted 'abstract' in interface method", 1, rule), 25 new TestDescriptor(TEST4, "all is well in interface method", 0, rule), 26 new TestDescriptor(TEST5, "wasted 'public' in interface field", 1, rule), 27 new TestDescriptor(TEST6, "wasted 'static' in interface field", 1, rule), 28 new TestDescriptor(TEST7, "wasted 'final' in interface field", 1, rule), 29 new TestDescriptor(TEST8, "wasted 'public static final' in interface field", 1, rule), 30 new TestDescriptor(TEST9, "OK in interface field", 0, rule), 31 new TestDescriptor(TEST10, "wasted 'public' in class nested in interface", 1, rule), 32 new TestDescriptor(TEST11, "wasted 'static' in class nested in interface", 1, rule), 33 new TestDescriptor(TEST12, "OK in class nested in interface", 0, rule), 34 new TestDescriptor(TEST13, "wasted 'public' in interface nested in interface", 1, rule), 35 new TestDescriptor(TEST14, "wasted 'static' in interface nested in interface", 1, rule), 36 new TestDescriptor(TEST15, "OK in interface nested in interface", 0, rule), 37 new TestDescriptor(TEST16, "wasted 'static' in interface nested in class", 1, rule), 38 new TestDescriptor(TEST17, "OK in interface nested in class", 0, rule), 39 new TestDescriptor(TEST18, "wasted 'public static final' in interface field inside another interface", 2, rule), 40 new TestDescriptor(TEST19, "OK in interface field inside another interface", 0, rule), 41 }); 42 } 43 44 private static final String TEST1 = 45 "public interface Foo {" + PMD.EOL + 46 " public void bar();" + PMD.EOL + 47 "}"; 48 49 private static final String TEST2 = 50 "public abstract class Foo {" + PMD.EOL + 51 " public abstract void bar();" + PMD.EOL + 52 "}"; 53 54 private static final String TEST3 = 55 "public interface Foo {" + PMD.EOL + 56 " abstract void bar();" + PMD.EOL + 57 "}"; 58 59 private static final String TEST4 = 60 "public interface Foo {" + PMD.EOL + 61 " void bar();" + PMD.EOL + 62 "}"; 63 64 private static final String TEST5 = 65 "public interface Foo {" + PMD.EOL + 66 " public int X = 0;" + PMD.EOL + 67 "}"; 68 69 private static final String TEST6 = 70 "public interface Foo {" + PMD.EOL + 71 " static int X = 0;" + PMD.EOL + 72 "}"; 73 74 private static final String TEST7 = 75 "public interface Foo {" + PMD.EOL + 76 " final int X = 0;" + PMD.EOL + 77 "}"; 78 79 private static final String TEST8 = 80 "public interface Foo {" + PMD.EOL + 81 " public static final int X = 0;" + PMD.EOL + 82 "}"; 83 84 private static final String TEST9 = 85 "public interface Foo {" + PMD.EOL + 86 " int X = 0;" + PMD.EOL + 87 "}"; 88 89 private static final String TEST10 = 90 "public interface Foo {" + PMD.EOL + 91 " public class Bar {}" + PMD.EOL + 92 "}"; 93 94 private static final String TEST11 = 95 "public interface Foo {" + PMD.EOL + 96 " static class Bar {}" + PMD.EOL + 97 "}"; 98 99 private static final String TEST12 = 100 "public interface Foo {" + PMD.EOL + 101 " class Bar {}" + PMD.EOL + 102 "}"; 103 104 private static final String TEST13 = 105 "public interface Foo {" + PMD.EOL + 106 " public interface Baz {}" + PMD.EOL + 107 "}"; 108 109 private static final String TEST14 = 110 "public interface Foo {" + PMD.EOL + 111 " static interface Baz {}" + PMD.EOL + 112 "}"; 113 114 private static final String TEST15 = 115 "public interface Foo {" + PMD.EOL + 116 " interface Baz {}" + PMD.EOL + 117 "}"; 118 119 private static final String TEST16 = 120 "public class Foo {" + PMD.EOL + 121 " public static interface Bar {}" + PMD.EOL + 122 "}"; 123 124 private static final String TEST17 = 125 "public class Foo {" + PMD.EOL + 126 " public interface Bar {}" + PMD.EOL + 127 "}"; 128 129 private static final String TEST18 = 130 "public interface Foo {" + PMD.EOL + 131 " public interface Bar {" + PMD.EOL + 132 " public static final int X = 0;" + PMD.EOL + 133 " }" + PMD.EOL + 134 "}"; 135 136 private static final String TEST19 = 137 "interface Foo {" + PMD.EOL + 138 " interface Bar {" + PMD.EOL + 139 " int X = 0;" + PMD.EOL + 140 " }" + PMD.EOL + 141 "}"; 142 143 }