added new JUnitStaticSuiteRule
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@914 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -1,5 +1,5 @@
|
||||
???? 2002 - 1.0rc2:
|
||||
Added new rule: JUnitSpellingRule
|
||||
Added new rules: JUnitSpellingRule, JUnitStaticSuiteRule
|
||||
Added new ruleset - junit.
|
||||
Fixed bug in PMD GUI - rules are now saved correctly.
|
||||
|
||||
|
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Sep 11, 2002
|
||||
* Time: 2:45:29 PM
|
||||
*/
|
||||
package test.net.sourceforge.pmd.rules;
|
||||
|
||||
import net.sourceforge.pmd.rules.JUnitStaticSuiteRule;
|
||||
|
||||
public class JUnitStaticSuiteRuleTest extends RuleTst {
|
||||
|
||||
public JUnitStaticSuiteRuleTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void test1() throws Throwable {
|
||||
runTest("JUnitStaticSuite1.java", 2, new JUnitStaticSuiteRule());
|
||||
}
|
||||
|
||||
public void test2() throws Throwable {
|
||||
runTest("JUnitStaticSuite2.java", 0, new JUnitStaticSuiteRule());
|
||||
}
|
||||
}
|
@ -19,6 +19,25 @@ public class Foo extends TestCase {
|
||||
public void setup() {} // oops, should be setUp
|
||||
public void TearDown() {} // oops, should be tearDown
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
|
||||
<rule name="JUnitStaticSuite"
|
||||
message="You have a suite() method that is not both public and static, so JUnit won't call it to get your TestSuite. Is that what you wanted to do?"
|
||||
class="net.sourceforge.pmd.rules.JUnitStaticSuiteRule">
|
||||
<description>
|
||||
The suite() method needs to be both public and static.
|
||||
</description>
|
||||
|
||||
<example>
|
||||
<![CDATA[
|
||||
import junit.framework.*;
|
||||
public class Foo extends TestCase {
|
||||
public void suite() {} // oops, should be static
|
||||
private static void suite() {} // oops, should be public
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
29
pmd/src/net/sourceforge/pmd/rules/JUnitStaticSuiteRule.java
Normal file
29
pmd/src/net/sourceforge/pmd/rules/JUnitStaticSuiteRule.java
Normal file
@ -0,0 +1,29 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Sep 11, 2002
|
||||
* Time: 2:27:46 PM
|
||||
*/
|
||||
package net.sourceforge.pmd.rules;
|
||||
|
||||
import net.sourceforge.pmd.AbstractRule;
|
||||
import net.sourceforge.pmd.RuleContext;
|
||||
import net.sourceforge.pmd.ast.ASTMethodDeclarator;
|
||||
import net.sourceforge.pmd.ast.AccessNode;
|
||||
|
||||
public class JUnitStaticSuiteRule extends AbstractRule {
|
||||
|
||||
public Object visit(ASTMethodDeclarator node, Object data) {
|
||||
if (!node.getImage().equals("suite")) {
|
||||
return data;
|
||||
}
|
||||
|
||||
AccessNode parent = (AccessNode)node.jjtGetParent();
|
||||
if (!parent.isPublic() || !parent.isStatic()) {
|
||||
RuleContext ctx = (RuleContext)data;
|
||||
ctx.getReport().addRuleViolation(createRuleViolation(ctx, node.getBeginColumn()));
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
}
|
4
pmd/test-data/JUnitStaticSuite1.java
Normal file
4
pmd/test-data/JUnitStaticSuite1.java
Normal file
@ -0,0 +1,4 @@
|
||||
public class JUnitStaticSuite1 {
|
||||
public TestSuite suite() {}
|
||||
private static TestSuite suite() {}
|
||||
}
|
3
pmd/test-data/JUnitStaticSuite2.java
Normal file
3
pmd/test-data/JUnitStaticSuite2.java
Normal file
@ -0,0 +1,3 @@
|
||||
public class JUnitStaticSuite2 {
|
||||
public static TestSuite suite() {}
|
||||
}
|
Reference in New Issue
Block a user