1 /***
2 * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3 */
4 package test.net.sourceforge.pmd.rules.strings;
5
6 import net.sourceforge.pmd.PMD;
7 import net.sourceforge.pmd.Rule;
8 import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
9 import test.net.sourceforge.pmd.testframework.TestDescriptor;
10
11 public class StringBufferInstantiationWithCharTest extends SimpleAggregatorTst {
12
13 private Rule rule;
14
15 public void setUp() throws Exception {
16 rule = findRule("strings", "StringBufferInstantiationWithChar");
17 }
18
19 public void testAll() {
20 runTests(new TestDescriptor[] {
21 new TestDescriptor(TEST1, "OK", 0, rule),
22 new TestDescriptor(TEST2, "failure case", 1, rule),
23 });
24 }
25
26 private static final String TEST1 =
27 "public class Foo {" + PMD.EOL +
28 " StringBuffer sb = new StringBuffer(\"c\");" + PMD.EOL +
29 "}";
30
31 private static final String TEST2 =
32 "public class Foo {" + PMD.EOL +
33 " StringBuffer sb = new StringBuffer('c');" + PMD.EOL +
34 "}";
35
36 }