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 CouplingBetweenObjectsTest extends SimpleAggregatorTst { 13 14 private Rule rule; 15 16 public void setUp() throws RuleSetNotFoundException { 17 rule = findRule("coupling", "CouplingBetweenObjects"); 18 rule.addProperty("threshold", "2"); 19 } 20 21 public void testAll() { 22 runTests(new TestDescriptor[]{ 23 new TestDescriptor(TEST1, "lots of coupling", 1, rule), 24 new TestDescriptor(TEST2, "no coupling", 0, rule), 25 new TestDescriptor(TEST3, "skip interfaces", 0, rule), 26 }); 27 } 28 29 private static final String TEST1 = 30 "import java.util.*;" + PMD.EOL + 31 "public class Foo {" + PMD.EOL + 32 " public List foo() {return null;}" + PMD.EOL + 33 " public ArrayList foo() {return null;}" + PMD.EOL + 34 " public Vector foo() {return null;}" + PMD.EOL + 35 "}"; 36 37 private static final String TEST2 = 38 "public class Foo {" + PMD.EOL + 39 "}"; 40 41 private static final String TEST3 = 42 "public interface Foo {" + PMD.EOL + 43 " public static final int FOO = 2; " + PMD.EOL + 44 "}"; 45 46 47 }