View Javadoc
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.rules.XPathRule; 9 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; 10 import test.net.sourceforge.pmd.testframework.TestDescriptor; 11 12 public class LongVariableRuleTest extends SimpleAggregatorTst { 13 14 private Rule rule; 15 16 public void setUp() { 17 rule = new XPathRule(); 18 rule.addProperty("xpath", "//VariableDeclaratorId[string-length(@Image) > 12]"); 19 } 20 21 public void testAll() { 22 runTests(new TestDescriptor[] { 23 new TestDescriptor(TEST1, "param", 1, rule), 24 new TestDescriptor(TEST2, "ok", 0, rule), 25 new TestDescriptor(TEST3, "local", 1, rule), 26 new TestDescriptor(TEST4, "field", 1, rule), 27 new TestDescriptor(TEST5, "for", 1, rule), 28 }); 29 } 30 31 private static final String TEST1 = 32 "public class LongVariableParam {" + PMD.EOL + 33 " public static void main(String argsWithExtraMustard[]) { " + PMD.EOL + 34 " // a should trigger it." + PMD.EOL + 35 " }" + PMD.EOL + 36 "}"; 37 38 private static final String TEST2 = 39 "public class LongVariableNone {" + PMD.EOL + 40 " public static void main(String args[]) {" + PMD.EOL + 41 " int bugleDeWump = -1;" + PMD.EOL + 42 " }" + PMD.EOL + 43 "}"; 44 45 private static final String TEST3 = 46 "public class LongVariableLocal {" + PMD.EOL + 47 "" + PMD.EOL + 48 " public static void main(String args[]) {" + PMD.EOL + 49 " int abcdefghijklmnopqrstuvwxyz = -1; " + PMD.EOL + 50 " // Should trigger ShortVariable rule." + PMD.EOL + 51 " }" + PMD.EOL + 52 "}"; 53 54 private static final String TEST4 = 55 "public class LongVariableFor {" + PMD.EOL + 56 " public static void main(String args[]) {" + PMD.EOL + 57 " for (int interestingIntIterator = 0; " + PMD.EOL + 58 " interestingIntIterator < 10; " + PMD.EOL + 59 " interestingIntIterator++) { } // Should trigger." + PMD.EOL + 60 " }" + PMD.EOL + 61 "}"; 62 63 private static final String TEST5 = 64 "public class LongVariableField {" + PMD.EOL + 65 " private int abcdefghijklmnopqrstuvwxyz; // Should cause a problem." + PMD.EOL + 66 "}"; 67 68 }

This page was automatically generated by Maven