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

This page was automatically generated by Maven