1
2
3
4
5 package net.sourceforge.pmd.lang.java.rule.design;
6
7 import net.sourceforge.pmd.PropertyDescriptor;
8 import net.sourceforge.pmd.Rule;
9 import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
10 import net.sourceforge.pmd.testframework.TestDescriptor;
11
12 import org.junit.Before;
13 import org.junit.Test;
14
15
16 public class UncommentedEmptyConstructorRuleTest extends SimpleAggregatorTst {
17
18 private Rule rule;
19 private TestDescriptor[] tests;
20
21 @Before
22 public void setUp() {
23 rule = findRule("java-design", "UncommentedEmptyConstructor");
24 tests = extractTestsFromXml(rule);
25 }
26
27 @Test
28 public void testDefault() {
29 runTests(tests);
30 }
31
32 @Test
33 public void testIgnoredConstructorInvocation() {
34 PropertyDescriptor<Boolean> descriptor = (PropertyDescriptor<Boolean>)rule.getPropertyDescriptor("ignoreExplicitConstructorInvocation");
35 rule.setProperty(descriptor, true);
36 TestDescriptor[] testDescriptors = new TestDescriptor[] {
37 new TestDescriptor(tests[0].getCode(), "simple failure", 1, rule),
38 new TestDescriptor(tests[1].getCode(), "only 'this(...)' failure", 1, rule),
39 new TestDescriptor(tests[2].getCode(), "only 'super(...)' failure", 1, rule),
40 new TestDescriptor(tests[3].getCode(), "single-line comment is OK", 0, rule),
41 new TestDescriptor(tests[4].getCode(), "multiple-line comment is OK", 0, rule),
42 new TestDescriptor(tests[5].getCode(), "Javadoc comment is OK", 0, rule),
43 new TestDescriptor(tests[6].getCode(), "ok", 0, rule),
44 new TestDescriptor(tests[7].getCode(), "with 'this(...)' ok", 0, rule),
45 new TestDescriptor(tests[8].getCode(), "with 'super(...)' ok", 0, rule),
46 new TestDescriptor(tests[9].getCode(), "private is ok", 0, rule), };
47 for (TestDescriptor testDescriptor : testDescriptors) {
48 testDescriptor.setReinitializeRule(false);
49 }
50 runTests(testDescriptors);
51 }
52
53 public static junit.framework.Test suite() {
54 return new junit.framework.JUnit4TestAdapter(UncommentedEmptyConstructorRuleTest.class);
55 }
56 }