1 package test.net.sourceforge.pmd.rules;
2
3 import net.sourceforge.pmd.PMD;
4 import net.sourceforge.pmd.rules.DoubleCheckedLockingRule;
5
6 public class DoubleCheckedLockingRuleTest extends SimpleAggregatorTst {
7
8 public void testAll() {
9 runTests(new TestDescriptor[] {
10 new TestDescriptor(TEST1, "simple ok", 0, new DoubleCheckedLockingRule()),
11 new TestDescriptor(TEST2, "simple failure", 1, new DoubleCheckedLockingRule()),
12 new TestDescriptor(TEST3, "skip interfaces", 0, new DoubleCheckedLockingRule()),
13 });
14 }
15
16 private static final String TEST1 =
17 "public class DoubleCheckedLockingRule1 {" + PMD.EOL +
18 " public void foo() {}" + PMD.EOL +
19 "}";
20
21 private static final String TEST2 =
22 "public class DoubleCheckedLockingRule2 {" + PMD.EOL +
23 " Object baz;" + PMD.EOL +
24 " Object bar() {" + PMD.EOL +
25 " if(baz == null) { //baz may be non-null yet not fully created" + PMD.EOL +
26 " synchronized(this){" + PMD.EOL +
27 " if(baz == null){" + PMD.EOL +
28 " baz = new Object();" + PMD.EOL +
29 " }" + PMD.EOL +
30 " }" + PMD.EOL +
31 " }" + PMD.EOL +
32 " return baz;" + PMD.EOL +
33 " }" + PMD.EOL +
34 "}";
35
36 private static final String TEST3 =
37 "public interface DoubleCheckedLockingRule3 {" + PMD.EOL +
38 " void foo();" + PMD.EOL +
39 "}";
40 }
This page was automatically generated by Maven