Began breaking up FunctionalTest

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@133 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-06-28 17:58:13 +00:00
parent 225ccd005a
commit 213e37f2a4
4 changed files with 106 additions and 59 deletions

View File

@ -1,4 +1,5 @@
update the xdocs:
-added new ruleset to Ant task - design
update run.bat to point to pmd-0.3.jar
update the changelog

View File

@ -21,64 +21,8 @@ public class FunctionalTest extends TestCase{
super(name);
}
public void testUnusedLocal1() {
Report report = process("Unused1.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal2() {
Report report = process("Unused2.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal3() {
Report report = process("Unused3.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal4() {
Report report = process("Unused4.java");
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal5() {
Report report = process("Unused5.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal6() {
Report report = process("Unused6.java");
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal7() {
Report report = process("Unused7.java");
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal8() {
Report report = process("Unused8.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new SystemPropsRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal9() {
Report report = process("Unused9.java");
assertEquals(2, report.countViolationsInCurrentFile());
Iterator i = report.violationsInCurrentFile();
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)i.next()).getRule());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)i.next()).getRule());
}
public void testUnusedLocal10() {
Report report = process("Unused10.java");
assertTrue(report.currentFileHasNoViolations());
}
/*
public void testEmptyCatchBlock() {
Report report = process("EmptyCatchBlock.java");
assertEquals(1, report.countViolationsInCurrentFile());
@ -185,6 +129,7 @@ public class FunctionalTest extends TestCase{
Report report = process("IfElseStmtsNeedBraces1.java");
assertEquals(1, report.countViolationsInCurrentFile());
}
*/
public void testIfElseStmtsMustUseBraces2() {
Report report = process("IfElseStmtsNeedBraces2.java");
assertTrue(report.currentFileHasNoViolations());

View File

@ -0,0 +1,91 @@
/*
* User: tom
* Date: Jun 28, 2002
* Time: 1:43:05 PM
*/
package test.net.sourceforge.pmd.rules;
import junit.framework.TestCase;
import net.sourceforge.pmd.*;
import net.sourceforge.pmd.rules.UnusedLocalVariableRule;
import net.sourceforge.pmd.rules.SystemPropsRule;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;
import java.io.FileNotFoundException;
public class UnusedLocalVariableTest extends TestCase {
public UnusedLocalVariableTest(String name) {
super(name);
}
public void testUnusedLocal1() {
Report report = process("Unused1.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal2() {
Report report = process("Unused2.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal3() {
Report report = process("Unused3.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal4() {
Report report = process("Unused4.java");
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal5() {
Report report = process("Unused5.java");
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal6() {
Report report = process("Unused6.java");
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal7() {
Report report = process("Unused7.java");
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal8() {
Report report = process("Unused8.java");
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal9() {
Report report = process("Unused9.java");
assertEquals(2, report.countViolationsInCurrentFile());
Iterator i = report.violationsInCurrentFile();
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)i.next()).getRule());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)i.next()).getRule());
}
public void testUnusedLocal10() {
Report report = process("Unused10.java");
assertTrue(report.currentFileHasNoViolations());
}
private Report process(String file) {
try {
PMD p = new PMD();
RuleContext ctx = new RuleContext();
ctx.setReport(new Report("xml", file));
p.processFile(file, getClass().getClassLoader().getResourceAsStream(file), new UnusedLocalVariableRule(), ctx);
return ctx.getReport();
} catch (FileNotFoundException fnfe) {
throw new RuntimeException("File " + file + " not found");
}
}
}

View File

@ -17,8 +17,7 @@ import java.util.ArrayList;
public class PMD {
public void processFile(String filename, InputStream is, String ruleSetType, RuleContext ctx) throws FileNotFoundException {
List rules = RuleFactory.createRules(ruleSetType);
public void processFile(String filename, InputStream is, List rules, RuleContext ctx) throws FileNotFoundException {
try {
InputStreamReader reader = new InputStreamReader(is);
JavaParser parser = new JavaParser(reader);
@ -39,6 +38,17 @@ public class PMD {
}
}
public void processFile(String filename, InputStream is, Rule rule, RuleContext ctx) throws FileNotFoundException {
List rules = new ArrayList();
rules.add(rule);
processFile(filename, is, rules, ctx);
}
public void processFile(String filename, InputStream is, String ruleSetType, RuleContext ctx) throws FileNotFoundException {
List rules = RuleFactory.createRules(ruleSetType);
processFile(filename, is, rules, ctx);
}
public void processFile(File file, String ruleSetType, RuleContext ctx) throws FileNotFoundException{
processFile(file.getAbsolutePath(), new FileInputStream(file), ruleSetType, ctx);
}