Refactored two test to spot using the deprecated ant class BuildFileTest

This commit is contained in:
Dionisio
2016-05-02 22:46:19 +02:00
parent 5e073d3bbf
commit 9ab1b23a5a
2 changed files with 52 additions and 20 deletions

View File

@ -3,9 +3,13 @@
*/ */
package net.sourceforge.pmd.ant; package net.sourceforge.pmd.ant;
import static org.junit.Assert.assertTrue;
import java.io.File; import java.io.File;
import org.apache.tools.ant.BuildFileTest; import org.apache.tools.ant.BuildFileRule;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
/** /**
@ -13,20 +17,20 @@ import org.junit.Test;
* @author Romain Pelisse <belaran@gmail.com> * @author Romain Pelisse <belaran@gmail.com>
* *
*/ */
public class CPDTaskTest extends BuildFileTest { public class CPDTaskTest {
@Override @Rule
protected void setUp() throws Exception { public final BuildFileRule buildRule = new BuildFileRule();
super.setUp();
configureProject("src/test/resources/net/sourceforge/pmd/ant/xml/cpdtasktest.xml"); @Before
public void setUp() {
buildRule.configureProject("src/test/resources/net/sourceforge/pmd/ant/xml/cpdtasktest.xml");
} }
@Test @Test
public void testBasic() { public void testBasic() {
executeTarget("testBasic"); buildRule.executeTarget("testBasic");
// FIXME: This clearly needs to be improved - but I don't like to write // FIXME: This clearly needs to be improved - but I don't like to write test, so feel free to contribute :)
// test,
// so feel free to contribute :)
assertTrue(new File("target/cpd.ant.tests").exists()); assertTrue(new File("target/cpd.ant.tests").exists());
} }
} }

View File

@ -3,34 +3,62 @@
*/ */
package net.sourceforge.pmd.ant; package net.sourceforge.pmd.ant;
import org.apache.tools.ant.BuildFileTest; import static org.junit.Assert.fail;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.BuildFileRule;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
public class PMDTaskTest extends BuildFileTest { public class PMDTaskTest {
@Override @Rule
protected void setUp() throws Exception { public final BuildFileRule buildRule = new BuildFileRule();
super.setUp();
configureProject("src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml"); @Before
public void setUp() {
buildRule.configureProject("src/test/resources/net/sourceforge/pmd/ant/xml/pmdtasktest.xml");
} }
@Test @Test
public void testFormatterWithNoToFileAttribute() { public void testFormatterWithNoToFileAttribute() {
expectBuildExceptionContaining("testFormatterWithNoToFileAttribute", "Valid Error Message", "toFile or toConsole needs to be specified in Formatter"); try {
buildRule.executeTarget("testFormatterWithNoToFileAttribute");
fail("This should throw an exception");
} catch (BuildException ex) {
Assert.assertEquals("toFile or toConsole needs to be specified in Formatter", ex.getMessage());
}
} }
@Test @Test
public void testNoRuleSets() { public void testNoRuleSets() {
expectBuildExceptionContaining("testNoRuleSets", "Valid Error Message", "No rulesets specified"); try {
buildRule.executeTarget("testNoRuleSets");
fail("This should throw an exception");
} catch (BuildException ex) {
Assert.assertEquals("No rulesets specified", ex.getMessage());
}
} }
@Test @Test
public void testBasic() { public void testBasic() {
executeTarget("testBasic"); buildRule.executeTarget("testBasic");
} }
@Test @Test
public void testInvalidLanguageVersion() { public void testInvalidLanguageVersion() {
expectBuildExceptionContaining("testInvalidLanguageVersion", "Fail requested.", "The following language is not supported:<sourceLanguage name=\"java\" version=\"42\" />."); try {
buildRule.executeTarget("testInvalidLanguageVersion");
Assert.assertEquals(
"The following language is not supported:<sourceLanguage name=\"java\" version=\"42\" />.",
buildRule.getLog());
fail("This should throw an exception");
} catch (BuildException ex) {
Assert.assertEquals(
"The following language is not supported:<sourceLanguage name=\"java\" version=\"42\" />.",
ex.getMessage());
}
} }
} }