Moving test cases from xml deffinition into JUnit test

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@4778 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Allan Caplan
2006-11-06 00:55:16 +00:00
parent 71334e29c3
commit 8580efe567
2 changed files with 24 additions and 32 deletions

View File

@ -1,7 +1,9 @@
package test.net.sourceforge.pmd.rules;
import net.sourceforge.pmd.PMD;
import net.sourceforge.pmd.Rule;
import test.net.sourceforge.pmd.testframework.SimpleAggregatorTst;
import test.net.sourceforge.pmd.testframework.TestDescriptor;
public class BrokenNullCheckTest extends SimpleAggregatorTst {
private Rule rule;
@ -11,6 +13,27 @@ public class BrokenNullCheckTest extends SimpleAggregatorTst {
}
public void testAll() {
runTests(rule);
runTests(new TestDescriptor[]{
new TestDescriptor(TEST1, "should be ||", 1, rule),
new TestDescriptor(TEST2, "should be &&", 1, rule),
});
}
private static final String TEST1 =
"public class Foo {" + PMD.EOL +
" List bar(List list) {" + PMD.EOL +
" if (list != null || !list.equals(buz)) {" + PMD.EOL +
" return list;" + PMD.EOL +
" }" + PMD.EOL +
" }" + PMD.EOL +
"}";
private static final String TEST2 =
"public class Foo {" + PMD.EOL +
" List bar(List list) {" + PMD.EOL +
" if (list == null && list.equals(buz)) {" + PMD.EOL +
" return list;" + PMD.EOL +
" }" + PMD.EOL +
" }" + PMD.EOL +
"}";
}

View File

@ -1,31 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<test-data>
<test-code>
<description><![CDATA[
should be ||
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
List bar(List list) {
if (list != null || !list.equals(buz)) {
return list;
}
}
}]]> </code>
</test-code>
<test-code>
<description><![CDATA[
should be &&
]]></description>
<expected-problems>1</expected-problems>
<code><![CDATA[
public class Foo {
List bar(List list) {
if (list == null && list.equals(buz)) {
return list;
}
}
}]]> </code>
</test-code>
</test-data>