test refactoring

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@140 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Tom Copeland
2002-06-28 19:07:15 +00:00
parent 8caf5aafb7
commit e87a3814b5
7 changed files with 54 additions and 70 deletions

View File

@ -70,15 +70,4 @@ public class FunctionalTest extends TestCase{
*/
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), RuleFactory.ALL, ctx);
return ctx.getReport();
} catch (FileNotFoundException fnfe) {
throw new RuntimeException("File " + file + " not found");
}
}
}

View File

@ -16,19 +16,19 @@ public class EmptyCatchBlockRuleTest extends RuleTst {
super(name);
}
public void testEmptyCatchBlock() {
Report report = process2("EmptyCatchBlock.java", new EmptyCatchBlockRule());
public void testEmptyCatchBlock() throws Throwable {
Report report = process("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());
public void testEmptyCatchBlock2() throws Throwable {
Report report = process("EmptyCatchBlock2.java", new EmptyCatchBlockRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testEmptyCatchBlock3() {
Report report = process2("EmptyCatchBlock3.java", new EmptyCatchBlockRule());
public void testEmptyCatchBlock3() throws Throwable {
Report report = process("EmptyCatchBlock3.java", new EmptyCatchBlockRule());
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new EmptyCatchBlockRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}

View File

@ -14,12 +14,12 @@ public class IfElseStmtsMustUseBracesRuleTest extends RuleTst {
super(name);
}
public void testIfElseStmtsMustUseBraces1() {
Report report = process2("IfElseStmtsNeedBraces1.java", new IfElseStmtsMustUseBracesRule());
public void testIfElseStmtsMustUseBraces1() throws Throwable {
Report report = process("IfElseStmtsNeedBraces1.java", new IfElseStmtsMustUseBracesRule());
assertEquals(1, report.countViolationsInCurrentFile());
}
public void testIfElseStmtsMustUseBraces2() {
Report report = process2("IfElseStmtsNeedBraces2.java", new IfElseStmtsMustUseBracesRule());
public void testIfElseStmtsMustUseBraces2() throws Throwable {
Report report = process("IfElseStmtsNeedBraces2.java", new IfElseStmtsMustUseBracesRule());
assertTrue(report.currentFileHasNoViolations());
}

View File

@ -30,6 +30,7 @@ public class RuleTst
Rule rule )
throws Throwable
{
/*
// Set up the Context
RuleContext ctx = new RuleContext();
ctx.setReport( new Report("xml", fileName) );
@ -49,18 +50,12 @@ public class RuleTst
// Return the report.
return ctx.getReport();
*/
PMD p = new PMD();
RuleContext ctx = new RuleContext();
ctx.setReport(new Report("xml", fileName));
p.processFile(fileName, getClass().getClassLoader().getResourceAsStream(fileName), rule, ctx);
return ctx.getReport();
}
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");
}
}
}

View File

@ -16,8 +16,8 @@ public class UnnecessaryTemporariesRuleTest extends RuleTst{
super(name);
}
public void testUnnecessaryTemporaries() {
Report report = process2("UnnecessaryTemporary.java", new UnnecessaryConversionTemporaryRule());
public void testUnnecessaryTemporaries() throws Throwable {
Report report = process("UnnecessaryTemporary.java", new UnnecessaryConversionTemporaryRule());
assertEquals(6, report.countViolationsInCurrentFile());
assertEquals(new UnnecessaryConversionTemporaryRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}

View File

@ -20,60 +20,60 @@ public class UnusedLocalVariableTest extends RuleTst {
super(name);
}
public void testUnusedLocal1() {
Report report = process2("Unused1.java", new UnusedLocalVariableRule());
public void testUnusedLocal1() throws Throwable {
Report report = process("Unused1.java", new UnusedLocalVariableRule());
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal2() {
Report report = process2("Unused2.java", new UnusedLocalVariableRule());
public void testUnusedLocal2() throws Throwable {
Report report = process("Unused2.java", new UnusedLocalVariableRule());
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal3() {
Report report = process2("Unused3.java", new UnusedLocalVariableRule());
public void testUnusedLocal3() throws Throwable {
Report report = process("Unused3.java", new UnusedLocalVariableRule());
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal4() {
Report report = process2("Unused4.java", new UnusedLocalVariableRule());
public void testUnusedLocal4() throws Throwable {
Report report = process("Unused4.java", new UnusedLocalVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal5() {
Report report = process2("Unused5.java", new UnusedLocalVariableRule());
public void testUnusedLocal5() throws Throwable {
Report report = process("Unused5.java", new UnusedLocalVariableRule());
assertEquals(1, report.countViolationsInCurrentFile());
assertEquals(new UnusedLocalVariableRule(), ((RuleViolation)report.violationsInCurrentFile().next()).getRule());
}
public void testUnusedLocal6() {
Report report = process2("Unused6.java", new UnusedLocalVariableRule());
public void testUnusedLocal6() throws Throwable {
Report report = process("Unused6.java", new UnusedLocalVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal7() {
Report report = process2("Unused7.java", new UnusedLocalVariableRule());
public void testUnusedLocal7() throws Throwable {
Report report = process("Unused7.java", new UnusedLocalVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal8() {
Report report = process2("Unused8.java", new UnusedLocalVariableRule());
public void testUnusedLocal8() throws Throwable {
Report report = process("Unused8.java", new UnusedLocalVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedLocal9() {
Report report = process2("Unused9.java", new UnusedLocalVariableRule());
public void testUnusedLocal9() throws Throwable {
Report report = process("Unused9.java", new UnusedLocalVariableRule());
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 = process2("Unused10.java", new UnusedLocalVariableRule());
public void testUnusedLocal10() throws Throwable {
Report report = process("Unused10.java", new UnusedLocalVariableRule());
assertTrue(report.currentFileHasNoViolations());
}

View File

@ -17,45 +17,45 @@ public class UnusedPrivateInstanceVariableRuleTest extends RuleTst {
super(name);
}
public void testUnusedPrivateInstanceVar1() {
Report report = process2("UnusedPrivateInstanceVar1.java", new UnusedPrivateInstanceVariableRule());
public void testUnusedPrivateInstanceVar1() throws Throwable {
Report report = process("UnusedPrivateInstanceVar1.java", new UnusedPrivateInstanceVariableRule());
assertEquals(1, report.countViolationsInCurrentFile());
Iterator i = report.violationsInCurrentFile();
assertEquals(new UnusedPrivateInstanceVariableRule(), ((RuleViolation)i.next()).getRule());
}
public void testUnusedPrivateInstanceVar2() {
Report report = process2("UnusedPrivateInstanceVar2.java", new UnusedPrivateInstanceVariableRule());
public void testUnusedPrivateInstanceVar2() throws Throwable {
Report report = process("UnusedPrivateInstanceVar2.java", new UnusedPrivateInstanceVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedPrivateInstanceVar3() {
Report report = process2("UnusedPrivateInstanceVar3.java", new UnusedPrivateInstanceVariableRule());
public void testUnusedPrivateInstanceVar3() throws Throwable {
Report report = process("UnusedPrivateInstanceVar3.java", new UnusedPrivateInstanceVariableRule());
assertEquals(1, report.countViolationsInCurrentFile());
Iterator i = report.violationsInCurrentFile();
assertEquals(new UnusedPrivateInstanceVariableRule(), ((RuleViolation)i.next()).getRule());
}
public void testUnusedPrivateInstanceVar4() {
Report report = process2("UnusedPrivateInstanceVar4.java", new UnusedPrivateInstanceVariableRule());
public void testUnusedPrivateInstanceVar4() throws Throwable {
Report report = process("UnusedPrivateInstanceVar4.java", new UnusedPrivateInstanceVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedPrivateInstanceVar6() {
Report report = process2("UnusedPrivateInstanceVar6.java", new UnusedPrivateInstanceVariableRule());
public void testUnusedPrivateInstanceVar6() throws Throwable {
Report report = process("UnusedPrivateInstanceVar6.java", new UnusedPrivateInstanceVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedPrivateInstanceVar7() {
Report report = process2("UnusedPrivateInstanceVar7.java", new UnusedPrivateInstanceVariableRule());
public void testUnusedPrivateInstanceVar7() throws Throwable {
Report report = process("UnusedPrivateInstanceVar7.java", new UnusedPrivateInstanceVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
public void testUnusedPrivateInstanceVar8() {
Report report = process2("UnusedPrivateInstanceVar8.java", new UnusedPrivateInstanceVariableRule());
public void testUnusedPrivateInstanceVar8() throws Throwable {
Report report = process("UnusedPrivateInstanceVar8.java", new UnusedPrivateInstanceVariableRule());
assertTrue(report.currentFileHasNoViolations());
}
/*
TODO - this tests unused variables in nested classes
public void testUnusedPrivateInstanceVar9() {
public void testUnusedPrivateInstanceVar9() throws Throwable {
Report report = process("UnusedPrivateInstanceVar9.java");
assertEquals(1, report.violationsInCurrentFile());
}