View Javadoc
1 package test.net.sourceforge.pmd.rules.design; 2 3 import net.sourceforge.pmd.PMD; 4 import net.sourceforge.pmd.rules.design.LooseCouplingRule; 5 import test.net.sourceforge.pmd.rules.SimpleAggregatorTst; 6 import test.net.sourceforge.pmd.rules.TestDescriptor; 7 8 public class LooseCouplingRuleTest extends SimpleAggregatorTst { 9 10 private LooseCouplingRule rule; 11 12 public void setUp() { 13 rule = new LooseCouplingRule(); 14 rule.setMessage("Avoid this stuff -> ''{0}''"); 15 } 16 17 public void testAll() { 18 runTests(new TestDescriptor[] { 19 new TestDescriptor(TEST1, "", 1, rule), 20 new TestDescriptor(TEST2, "", 0, rule), 21 new TestDescriptor(TEST3, "", 0, rule), 22 new TestDescriptor(TEST4, "", 0, rule), 23 new TestDescriptor(TEST5, "", 1, rule), 24 new TestDescriptor(TEST6, "", 2, rule), 25 new TestDescriptor(TEST7, "", 2, rule), 26 new TestDescriptor(TEST8, "", 1, rule), 27 new TestDescriptor(TEST9, "Vector could be List", 1, rule), 28 }); 29 } 30 31 private static final String TEST1 = 32 "import java.util.*;" + PMD.EOL + 33 "public class LooseCoupling1 {" + PMD.EOL + 34 " public HashSet getFoo() {" + PMD.EOL + 35 " return new HashSet();" + PMD.EOL + 36 " }" + PMD.EOL + 37 "}"; 38 39 private static final String TEST2 = 40 "import java.util.*;" + PMD.EOL + 41 "public class LooseCoupling2 {" + PMD.EOL + 42 " public Map getFoo() {" + PMD.EOL + 43 " return new HashMap();" + PMD.EOL + 44 " }" + PMD.EOL + 45 "}"; 46 47 private static final String TEST3 = 48 "public class LooseCoupling3 {" + PMD.EOL + 49 " public void foo() {}" + PMD.EOL + 50 "}"; 51 52 private static final String TEST4 = 53 "import java.util.*;" + PMD.EOL + 54 "public class LooseCoupling1 {" + PMD.EOL + 55 " private Set fooSet = new HashSet(); // OK" + PMD.EOL + 56 " public Set getFoo() {" + PMD.EOL + 57 " return fooSet;" + PMD.EOL + 58 " }" + PMD.EOL + 59 "}"; 60 61 private static final String TEST5 = 62 "import java.util.*;" + PMD.EOL + 63 "public class LooseCoupling5 {" + PMD.EOL + 64 " private HashSet fooSet = new HashSet(); // NOT OK" + PMD.EOL + 65 " public Set getFoo() {" + PMD.EOL + 66 " return fooSet;" + PMD.EOL + 67 " }" + PMD.EOL + 68 "}"; 69 70 private static final String TEST6 = 71 "import java.util.*;" + PMD.EOL + 72 "public class LooseCoupling1 {" + PMD.EOL + 73 " private HashSet fooSet = new HashSet(); // NOT OK" + PMD.EOL + 74 " public HashSet getFoo() { // NOT OK" + PMD.EOL + 75 " return fooSet;" + PMD.EOL + 76 " }" + PMD.EOL + 77 "}"; 78 79 private static final String TEST7 = 80 "import java.util.*;" + PMD.EOL + 81 "public class LooseCoupling7 {" + PMD.EOL + 82 " private HashSet fooSet = new HashSet();" + PMD.EOL + 83 " private HashMap fooMap = new HashMap();" + PMD.EOL + 84 "}"; 85 86 private static final String TEST8 = 87 "import java.util.*;" + PMD.EOL + 88 "public class LooseCoupling8 {" + PMD.EOL + 89 " public void foo(HashMap bar) {}" + PMD.EOL + 90 "}"; 91 92 private static final String TEST9 = 93 "import java.util.*;" + PMD.EOL + 94 "public class LooseCoupling9 {" + PMD.EOL + 95 " public void foo(Vector bar) {}" + PMD.EOL + 96 "}"; 97 98 }

This page was automatically generated by Maven