moving stuff out of FunctionalTest
git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@134 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
@ -23,23 +23,6 @@ public class FunctionalTest extends TestCase{
|
||||
|
||||
|
||||
/*
|
||||
public void testEmptyCatchBlock() {
|
||||
Report report = process("EmptyCatchBlock.java");
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testEmptyCatchBlock2() {
|
||||
Report report = process("EmptyCatchBlock2.java");
|
||||
assertTrue(report.currentFileHasNoViolations());
|
||||
}
|
||||
|
||||
public void testEmptyCatchBlock3() {
|
||||
Report report = process("EmptyCatchBlock3.java");
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testUnnecessaryTemporaries() {
|
||||
Report report = process("UnnecessaryTemporary.java");
|
||||
assertEquals(6, report.countViolationsInCurrentFile());
|
||||
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* User: tom
|
||||
* Date: Jun 28, 2002
|
||||
* Time: 1:56:19 PM
|
||||
*/
|
||||
package test.net.sourceforge.pmd.rules;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sourceforge.pmd.Report;
|
||||
import net.sourceforge.pmd.RuleViolation;
|
||||
import net.sourceforge.pmd.rules.EmptyCatchBlockRule;
|
||||
|
||||
public class EmptyCatchBlockRuleTest extends RuleTst {
|
||||
|
||||
public EmptyCatchBlockRuleTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testEmptyCatchBlock() {
|
||||
Report report = process2("EmptyCatchBlock.java", new EmptyCatchBlockRule());
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testEmptyCatchBlock2() {
|
||||
Report report = process2("EmptyCatchBlock2.java", new EmptyCatchBlockRule());
|
||||
assertTrue(report.currentFileHasNoViolations());
|
||||
}
|
||||
|
||||
public void testEmptyCatchBlock3() {
|
||||
Report report = process2("EmptyCatchBlock3.java", new EmptyCatchBlockRule());
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -8,6 +8,7 @@ package test.net.sourceforge.pmd.rules;
|
||||
*/
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
@ -15,6 +16,7 @@ import java.util.ArrayList;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import net.sourceforge.pmd.*;
|
||||
import net.sourceforge.pmd.rules.UnusedLocalVariableRule;
|
||||
import net.sourceforge.pmd.ast.*;
|
||||
|
||||
public class RuleTst
|
||||
@ -50,4 +52,15 @@ public class RuleTst
|
||||
|
||||
}
|
||||
|
||||
public Report process2(String file, Rule rule) {
|
||||
try {
|
||||
PMD p = new PMD();
|
||||
RuleContext ctx = new RuleContext();
|
||||
ctx.setReport(new Report("xml", file));
|
||||
p.processFile(file, getClass().getClassLoader().getResourceAsStream(file), rule, ctx);
|
||||
return ctx.getReport();
|
||||
} catch (FileNotFoundException fnfe) {
|
||||
throw new RuntimeException("File " + file + " not found");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -15,57 +15,57 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
public class UnusedLocalVariableTest extends TestCase {
|
||||
public class UnusedLocalVariableTest extends RuleTst {
|
||||
public UnusedLocalVariableTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
public void testUnusedLocal1() {
|
||||
Report report = process("Unused1.java");
|
||||
Report report = process2("Unused1.java", new UnusedLocalVariableRule());
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testUnusedLocal2() {
|
||||
Report report = process("Unused2.java");
|
||||
Report report = process2("Unused2.java", new UnusedLocalVariableRule());
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testUnusedLocal3() {
|
||||
Report report = process("Unused3.java");
|
||||
Report report = process2("Unused3.java", new UnusedLocalVariableRule());
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testUnusedLocal4() {
|
||||
Report report = process("Unused4.java");
|
||||
Report report = process2("Unused4.java", new UnusedLocalVariableRule());
|
||||
assertTrue(report.currentFileHasNoViolations());
|
||||
}
|
||||
|
||||
public void testUnusedLocal5() {
|
||||
Report report = process("Unused5.java");
|
||||
Report report = process2("Unused5.java", new UnusedLocalVariableRule());
|
||||
assertEquals(1, report.countViolationsInCurrentFile());
|
||||
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
|
||||
}
|
||||
|
||||
public void testUnusedLocal6() {
|
||||
Report report = process("Unused6.java");
|
||||
Report report = process2("Unused6.java", new UnusedLocalVariableRule());
|
||||
assertTrue(report.currentFileHasNoViolations());
|
||||
}
|
||||
|
||||
public void testUnusedLocal7() {
|
||||
Report report = process("Unused7.java");
|
||||
Report report = process2("Unused7.java", new UnusedLocalVariableRule());
|
||||
assertTrue(report.currentFileHasNoViolations());
|
||||
}
|
||||
|
||||
public void testUnusedLocal8() {
|
||||
Report report = process("Unused8.java");
|
||||
Report report = process2("Unused8.java", new UnusedLocalVariableRule());
|
||||
assertTrue(report.currentFileHasNoViolations());
|
||||
}
|
||||
|
||||
public void testUnusedLocal9() {
|
||||
Report report = process("Unused9.java");
|
||||
Report report = process2("Unused9.java", new UnusedLocalVariableRule());
|
||||
assertEquals(2, report.countViolationsInCurrentFile());
|
||||
Iterator i = report.violationsInCurrentFile();
|
||||
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)i.next()).getRule());
|
||||
@ -73,19 +73,8 @@ public class UnusedLocalVariableTest extends TestCase {
|
||||
}
|
||||
|
||||
public void testUnusedLocal10() {
|
||||
Report report = process("Unused10.java");
|
||||
Report report = process2("Unused10.java", new UnusedLocalVariableRule());
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user