This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git
The following commit(s) were added to refs/heads/master by this push:
new 010a1b1 [MPMD-412] Remove unused code and otherwise cleanup tests
(#178)
010a1b1 is described below
commit 010a1b1122ab0614c01e7822b4da65c8a62ea91a
Author: Elliotte Rusty Harold <[email protected]>
AuthorDate: Mon Apr 21 18:55:08 2025 +0000
[MPMD-412] Remove unused code and otherwise cleanup tests (#178)
* Remove unused code and otherwise cleanuop tests
---
.../apache/maven/plugins/pmd/PmdReportTest.java | 23 ++++++++++------------
.../plugins/pmd/PmdViolationCheckMojoTest.java | 21 ++++++++++----------
.../pmd-check-exception-test-plugin-config.xml | 5 -----
...d-check-default-configuration-plugin-config.xml | 1 -
4 files changed, 21 insertions(+), 29 deletions(-)
diff --git a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
index 26da490..37e9898 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdReportTest.java
@@ -255,11 +255,9 @@ public class PmdReportTest extends
AbstractPmdReportTestCase {
mockServer.stop();
}
- private int determineFreePort() {
+ private int determineFreePort() throws IOException {
try (ServerSocket socket = new ServerSocket(0)) {
return socket.getLocalPort();
- } catch (IOException e) {
- throw new RuntimeException("Couldn't find a free port.", e);
}
}
@@ -349,25 +347,24 @@ public class PmdReportTest extends
AbstractPmdReportTestCase {
mojo, "compileSourceRoots",
mojo.getProject().getCompileSourceRoots());
generateReport(mojo, testPom);
- fail("Must throw MavenReportException.");
- } catch (Exception e) {
- assertTrue(true);
+ fail("Must nest MavenReportException.");
+ } catch (MojoExecutionException e) {
+ assertTrue(e.getCause() instanceof MavenReportException);
}
}
public void testInvalidTargetJdk() throws Exception {
try {
- generateReport(getGoal(),
"empty-report/invalid-format/invalid-target-jdk-plugin-config.xml");
+ generateReport(getGoal(),
"invalid-format/invalid-target-jdk-plugin-config.xml");
- fail("Must throw MavenReportException.");
- } catch (Exception e) {
- assertTrue(true);
+ fail("Must nest MavenReportException.");
+ } catch (MojoExecutionException e) {
+ assertTrue(e.getCause() instanceof MavenReportException);
}
}
/**
- * verify the pmd.xml file is included in the reports when requested.
- * @throws Exception
+ * Verify the pmd.xml file is included in the reports when requested.
*/
public void testIncludeXmlInReports() throws Exception {
File generatedReport =
@@ -559,7 +556,7 @@ public class PmdReportTest extends
AbstractPmdReportTestCase {
assertFalse(
"Exclusion of an exact source directory not working",
str.contains("OverrideBothEqualsAndHashcode"));
assertFalse(
- "Exclusion of basedirectory with subdirectories not working
(MPMD-178)",
+ "Exclusion of base directory with subdirectories not working
(MPMD-178)",
str.contains("JumbledIncrementer"));
}
diff --git
a/src/test/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojoTest.java
b/src/test/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojoTest.java
index c54cb6c..61d7527 100644
--- a/src/test/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojoTest.java
+++ b/src/test/java/org/apache/maven/plugins/pmd/PmdViolationCheckMojoTest.java
@@ -21,6 +21,7 @@ package org.apache.maven.plugins.pmd;
import java.io.File;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
/**
* @author <a href="mailto:[email protected]">Maria Odea Ching</a>
@@ -42,7 +43,7 @@ public class PmdViolationCheckMojoTest extends
AbstractPmdReportTestCase {
mojo.execute();
fail("MojoFailureException should be thrown.");
- } catch (final Exception e) {
+ } catch (final MojoFailureException e) {
assertTrue(
e.getMessage().startsWith("PMD " +
AbstractPmdReport.getPmdVersion() + " has found 8 violations."));
}
@@ -56,8 +57,6 @@ public class PmdViolationCheckMojoTest extends
AbstractPmdReportTestCase {
"src/test/resources/unit/default-configuration/pmd-check-notfailonviolation-plugin-config.xml");
final PmdViolationCheckMojo pmdViolationMojo = (PmdViolationCheckMojo)
lookupMojo(getGoal(), testPom);
pmdViolationMojo.execute();
-
- assertTrue(true);
}
public void testMaxAllowedViolations() throws Exception {
@@ -90,16 +89,17 @@ public class PmdViolationCheckMojoTest extends
AbstractPmdReportTestCase {
File testPom = new File(
getBasedir(),
"src/test/resources/unit/default-configuration/pmd-check-failonpriority-plugin-config.xml");
- PmdViolationCheckMojo pmdViolationMojo = (PmdViolationCheckMojo)
lookupMojo(getGoal(), testPom);
- pmdViolationMojo.execute();
+ PmdViolationCheckMojo pmdViolationCheckMojo = (PmdViolationCheckMojo)
lookupMojo(getGoal(), testPom);
+ pmdViolationCheckMojo.execute();
testPom = new File(
getBasedir(),
"src/test/resources/unit/default-configuration/pmd-check-failandwarnonpriority-plugin-config.xml");
- pmdViolationMojo = (PmdViolationCheckMojo) lookupMojo(getGoal(),
testPom);
+ pmdViolationCheckMojo = (PmdViolationCheckMojo) lookupMojo(getGoal(),
testPom);
+
try {
- pmdViolationMojo.execute();
- fail("Exception Expected");
+ pmdViolationCheckMojo.execute();
+ fail("MojoFailureException expected");
} catch (final MojoFailureException e) {
assertTrue(e.getMessage()
.startsWith("PMD " + AbstractPmdReport.getPmdVersion()
@@ -113,11 +113,12 @@ public class PmdViolationCheckMojoTest extends
AbstractPmdReportTestCase {
getBasedir(),
"src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml");
final PmdViolationCheckMojo mojo = (PmdViolationCheckMojo)
lookupMojo(getGoal(), testPom);
+ mojo.project = new MavenProject();
mojo.execute();
fail("MojoFailureException should be thrown.");
- } catch (final Exception e) {
- assertTrue(true);
+ } catch (final MojoFailureException e) {
+ assertNotNull(e.getMessage());
}
}
diff --git
a/src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml
b/src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml
index 90532ab..7091107 100644
---
a/src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml
+++
b/src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml
@@ -23,9 +23,7 @@ under the License.
<artifactId>custom-configuration</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
- <inceptionYear>2006</inceptionYear>
<name>Maven PMD Violation Check Custom Configuration Test</name>
- <url>http://maven.apache.org</url>
<build>
<finalName>custom-configuration</finalName>
<plugins>
@@ -33,11 +31,8 @@ under the License.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<configuration>
-
<sourceDirectory>${basedir}/src/test/resources/unit/custom-configuration</sourceDirectory>
<targetDirectory>${basedir}/target/test/unit/custom-configuration/target</targetDirectory>
-
<rulesetsTargetDirectory>${basedir}/target/test/unit/custom-configuration/target/pmd/rulesets</rulesetsTargetDirectory>
<failOnViolation>false</failOnViolation>
- <language>java</language>
</configuration>
</plugin>
</plugins>
diff --git
a/src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml
b/src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml
index c1a4e3c..d715f86 100644
---
a/src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml
+++
b/src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml
@@ -37,7 +37,6 @@ under the License.
<targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory>
<failOnViolation>true</failOnViolation>
<printFailingErrors>true</printFailingErrors>
-<!-- <failurePriority>5</failurePriority> -->
</configuration>
</plugin>
</plugins>