pmd: AntTask Tests helper

As a workaround is needed to have the AntTask related to work in Maven
I've moved it into a separate abstract class that will be shared betweeen
the PMD AntTask tests and the upcoming CPD AntTask tests.
This commit is contained in:
Romain PELISSE committed 2012-12-21 20:15:29 +01:00
1 parent 5eb160de5b
commit dd754cb808
2 files changed
+52 -14

No files matched your search

@@ -0,0 +1,47 @@
package net.sourceforge.pmd.ant;
import static java.io.File.separator;
import org.apache.tools.ant.BuildFileTest;
/**
* Quite an ugly classe, arguably useful for just 2 units test - nevertheless as
* there is a workaround that must be shared by both tests (PMD and CPD's) I felt
* compelled to move it to a single classes.
*
* @author Romain Pelisse <belaran@gmail.com>
*
*/
public abstract class AbstractAntTestHelper extends BuildFileTest {
protected String pathToTestScript;
protected String antTestScriptFilename;
public String mvnWorkaround;
public AbstractAntTestHelper() {
mvnWorkaround = "pmd/ant/xml";
pathToTestScript = "target/test-classes/net/sourceforge/" + mvnWorkaround;
}
@Override
public void setUp() {
validatePostConstruct();
// initialize Ant
configureProject(pathToTestScript + separator + antTestScriptFilename);
if (!project.getBaseDir().toString().endsWith(mvnWorkaround)) {
// when running from maven, the path needs to be adapted...
// FIXME: this is more a workaround than a good solution...
project.setBasedir(project.getBaseDir().toString()
+ separator + pathToTestScript);
}
}
private void validatePostConstruct() {
if ( pathToTestScript == null || "".equals(pathToTestScript) ||
antTestScriptFilename == null || "".equals(antTestScriptFilename) ||
mvnWorkaround == null || "".equals(mvnWorkaround) )
throw new IllegalStateException("Unit tests for Ant script badly initialized");
}
}
@@ -3,22 +3,13 @@
*/
package net.sourceforge.pmd.ant;
import org.apache.tools.ant.BuildFileTest;
import org.junit.Test;
public class PMDTaskTest extends BuildFileTest {
public class PMDTaskTest extends AbstractAntTestHelper {
@Override
public void setUp() {
// initialize Ant
configureProject("target/test-classes/net/sourceforge/pmd/ant/xml/pmdtasktest.xml");
if (!project.getBaseDir().toString().endsWith("pmd/ant/xml")) {
// when running from maven, the path needs to be adapted...
// FIXME: this is more a workaround than a good solution...
project.setBasedir(project.getBaseDir().toString()
+ "/target/test-classes/net/sourceforge/pmd/ant/xml");
}
}
public PMDTaskTest() {
super.antTestScriptFilename = "pmdtasktest.xml";
}
@Test
public void testNoFormattersValidation() {
@@ -96,7 +87,7 @@ public class PMDTaskTest extends BuildFileTest {
public void testInvalidLanguageVersion() {
expectBuildExceptionContaining("testInvalidLanguageVersion", "Fail requested.", "The <version> element, if used, must be one of 'java 1.3', 'java 1.4', 'java 1.5', 'java 1.6', 'java 1.7'.");
}
@Test
public void testExplicitRuleInRuleSet() {
executeTarget("testExplicitRuleInRuleSet");