forked from phoedos/pmd
cleanup of test using reinitialization in XML test-data file
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4850 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -5,32 +5,16 @@ package test.net.sourceforge.pmd.rules;
|
|||||||
|
|
||||||
import net.sourceforge.pmd.Rule;
|
import net.sourceforge.pmd.Rule;
|
||||||
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||||
import test.net.sourceforge.pmd.testframework.TestDescriptor;
|
|
||||||
|
|
||||||
public class CloseResourceTest extends SimpleAggregatorTst {
|
public class CloseResourceTest extends SimpleAggregatorTst {
|
||||||
private Rule rule;
|
private Rule rule;
|
||||||
private TestDescriptor[] tests;
|
|
||||||
|
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
rule = findRule("design", "CloseResource");
|
rule = findRule("design", "CloseResource");
|
||||||
tests = extractTestsFromXml(rule);
|
|
||||||
rule.addProperty("types", "Connection,Statement,ResultSet"); //Default
|
rule.addProperty("types", "Connection,Statement,ResultSet"); //Default
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAll() {
|
public void testAll() {
|
||||||
runTests(new TestDescriptor[] {tests[0], tests[1], tests[2], tests[3], tests[4]});
|
runTests(rule);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMultipleProperties(){
|
|
||||||
runTest(tests[5]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testTypes(){
|
|
||||||
runTest(tests[6]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testPropertySetter(){
|
|
||||||
runTest(tests[7]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,33 +1,19 @@
|
|||||||
|
/**
|
||||||
|
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
||||||
|
*/
|
||||||
|
package test.net.sourceforge.pmd.rules;
|
||||||
|
|
||||||
/**
|
import net.sourceforge.pmd.Rule;
|
||||||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html
|
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
||||||
*/
|
|
||||||
package test.net.sourceforge.pmd.rules;
|
public class EmptyCatchBlockRuleTest extends SimpleAggregatorTst {
|
||||||
|
private Rule rule;
|
||||||
import net.sourceforge.pmd.Rule;
|
|
||||||
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
|
public void setUp() {
|
||||||
import test.net.sourceforge.pmd.testframework.TestDescriptor;
|
rule = findRule("basic", "EmptyCatchBlock");
|
||||||
|
}
|
||||||
public class EmptyCatchBlockRuleTest extends SimpleAggregatorTst {
|
|
||||||
private Rule rule;
|
public void testAll() {
|
||||||
private TestDescriptor[] tests;
|
runTests(rule);
|
||||||
|
}
|
||||||
public void setUp() {
|
}
|
||||||
rule = findRule("basic", "EmptyCatchBlock");
|
|
||||||
tests = extractTestsFromXml(rule);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testAll() {
|
|
||||||
runTests(tests);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testCommentedBlocksAllowed() {
|
|
||||||
rule.addProperty("allowCommentedBlocks", "true");
|
|
||||||
runTests(new TestDescriptor[]{
|
|
||||||
new TestDescriptor(tests[7].getCode(), "single-line comment is OK", 0, rule),
|
|
||||||
new TestDescriptor(tests[8].getCode(), "multiple-line comment is OK", 0, rule),
|
|
||||||
new TestDescriptor(tests[9].getCode(), "Javadoc comment is OK", 0, rule),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ Bad, no closeTargets properties for statements
|
|||||||
<expected-problems>2</expected-problems>
|
<expected-problems>2</expected-problems>
|
||||||
<code-ref id="executeQuery"/>
|
<code-ref id="executeQuery"/>
|
||||||
</test-code>
|
</test-code>
|
||||||
<test-code>
|
<test-code reinitializeRule="true">
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
Ok, closeTargets properties for statements
|
Ok, closeTargets properties for statements
|
||||||
]]></description>
|
]]></description>
|
||||||
@ -96,7 +96,7 @@ Ok, closeTargets properties for statements
|
|||||||
<expected-problems>0</expected-problems>
|
<expected-problems>0</expected-problems>
|
||||||
<code-ref id="executeQuery"/>
|
<code-ref id="executeQuery"/>
|
||||||
</test-code>
|
</test-code>
|
||||||
<test-code>
|
<test-code reinitializeRule="true">
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
Add type param
|
Add type param
|
||||||
]]></description>
|
]]></description>
|
||||||
@ -115,7 +115,7 @@ readExternal(aStream);
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
<test-code>
|
<test-code reinitializeRule="true">
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
OK
|
OK
|
||||||
]]></description>
|
]]></description>
|
||||||
|
@ -103,48 +103,75 @@ public class Foo {
|
|||||||
}
|
}
|
||||||
]]></code>
|
]]></code>
|
||||||
</test-code>
|
</test-code>
|
||||||
<!-- Commented blocks disallowed -->
|
<!-- Commented blocks -->
|
||||||
<test-code>
|
<code-fragment id="single-line comment"><![CDATA[
|
||||||
<description><![CDATA[
|
|
||||||
single-line comment is not OK
|
|
||||||
]]></description>
|
|
||||||
<expected-problems>1</expected-problems>
|
|
||||||
<code><![CDATA[
|
|
||||||
public class Foo {
|
public class Foo {
|
||||||
void bar() {
|
void bar() {
|
||||||
try {} catch (Exception e) { // Commented
|
try {} catch (Exception e) { // Commented
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]]></code>
|
]]></code-fragment>
|
||||||
</test-code>
|
|
||||||
<test-code>
|
<test-code>
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
multiple-line comment is not OK
|
single-line comment is not OK
|
||||||
]]></description>
|
]]></description>
|
||||||
<expected-problems>1</expected-problems>
|
<expected-problems>1</expected-problems>
|
||||||
<code><![CDATA[
|
<code-ref id="single-line comment"/>
|
||||||
|
</test-code>
|
||||||
|
<test-code reinitializeRule="1">
|
||||||
|
<description><![CDATA[
|
||||||
|
single-line comment is OK
|
||||||
|
]]></description>
|
||||||
|
<rule-property name="allowCommentedBlocks">true</rule-property>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code-ref id="single-line comment"/>
|
||||||
|
</test-code>
|
||||||
|
<code-fragment id="multiple-line comment"><![CDATA[
|
||||||
public class Foo {
|
public class Foo {
|
||||||
void bar() {
|
void bar() {
|
||||||
try {} catch (Exception e) { /* Commented */
|
try {} catch (Exception e) { /* Commented */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]]></code>
|
]]></code-fragment>
|
||||||
</test-code>
|
|
||||||
<test-code>
|
<test-code>
|
||||||
<description><![CDATA[
|
<description><![CDATA[
|
||||||
Javadoc comment is not OK
|
multiple-line comment is not OK
|
||||||
]]></description>
|
]]></description>
|
||||||
<expected-problems>1</expected-problems>
|
<expected-problems>1</expected-problems>
|
||||||
<code><![CDATA[
|
<code-ref id="multiple-line comment"/>
|
||||||
|
</test-code>
|
||||||
|
<test-code reinitializeRule="true">
|
||||||
|
<description><![CDATA[
|
||||||
|
multiple-line comment is OK
|
||||||
|
]]></description>
|
||||||
|
<rule-property name="allowCommentedBlocks">true</rule-property>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code-ref id="multiple-line comment"/>
|
||||||
|
</test-code>
|
||||||
|
<code-fragment id="javadoc comment"><![CDATA[
|
||||||
public class Foo {
|
public class Foo {
|
||||||
void bar() {
|
void bar() {
|
||||||
try {} catch (Exception e) { /** Commented */
|
try {} catch (Exception e) { /** Commented */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]]></code>
|
]]></code-fragment>
|
||||||
|
<test-code>
|
||||||
|
<description><![CDATA[
|
||||||
|
Javadoc comment is not OK
|
||||||
|
]]></description>
|
||||||
|
<expected-problems>1</expected-problems>
|
||||||
|
<code-ref id="javadoc comment"/>
|
||||||
</test-code>
|
</test-code>
|
||||||
<!-- END Commented blocks disallowed -->
|
<test-code reinitializeRule="true">
|
||||||
|
<description><![CDATA[
|
||||||
|
Javadoc comment is OK
|
||||||
|
]]></description>
|
||||||
|
<rule-property name="allowCommentedBlocks">true</rule-property>
|
||||||
|
<expected-problems>0</expected-problems>
|
||||||
|
<code-ref id="javadoc comment"/>
|
||||||
|
</test-code>
|
||||||
|
<!-- END Commented blocks -->
|
||||||
</test-data>
|
</test-data>
|
||||||
|
Reference in New Issue
Block a user