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