1 package test.net.sourceforge.pmd.rules.optimization; 2 3 import net.sourceforge.pmd.PMD; 4 import net.sourceforge.pmd.Rule; 5 import net.sourceforge.pmd.RuleSetNotFoundException; 6 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst; 7 import test.net.sourceforge.pmd.testframework.TestDescriptor; 8 9 public class UseStringBufferForStringAppendsTest extends SimpleAggregatorTst { 10 private Rule rule; 11 12 public void setUp() throws RuleSetNotFoundException { 13 rule = findRule("optimizations", "UseStringBufferForStringAppends"); 14 } 15 16 public void testAll() { 17 runTests(new TestDescriptor[]{ 18 new TestDescriptor(TEST1, "failure case", 1, rule), 19 new TestDescriptor(TEST2, "startsWith multiple chars", 0, rule), 20 }); 21 } 22 23 private static final String TEST1 = 24 "public class Foo {" + PMD.EOL + 25 " public void bar() {" + PMD.EOL + 26 " String x;" + PMD.EOL + 27 " x = \"foo\";" + PMD.EOL + 28 " x += \"bar\";" + PMD.EOL + 29 " }" + PMD.EOL + 30 "}"; 31 32 private static final String TEST2 = 33 "public class Foo {" + PMD.EOL + 34 " public boolean bar(Fiddle x) {" + PMD.EOL + 35 " return x.startsWith(\"abc\");" + PMD.EOL + 36 " }" + PMD.EOL + 37 "}"; 38 39 }