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 26da4903..37e98986 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 void testFileURL() throws Exception { 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 void testInvalidFormat() throws Exception { 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 void testPMDExcludeRootsShouldExcludeSubdirectories() throws Exception { 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 c54cb6c9..61d75277 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 @@ import java.io.File; import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.project.MavenProject; /** * @author Maria Odea Ching @@ -42,7 +43,7 @@ public void testDefaultConfiguration() throws Exception { 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 void testNotFailOnViolation() throws Exception { "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 void testFailurePriority() throws Exception { 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 void testException() throws Exception { 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 90532abb..70911072 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. custom-configuration jar 1.0-SNAPSHOT - 2006 Maven PMD Violation Check Custom Configuration Test - http://maven.apache.org custom-configuration @@ -33,11 +31,8 @@ under the License. org.apache.maven.plugins maven-pmd-plugin - ${basedir}/src/test/resources/unit/custom-configuration ${basedir}/target/test/unit/custom-configuration/target - ${basedir}/target/test/unit/custom-configuration/target/pmd/rulesets false - java 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 c1a4e3c8..d715f865 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. ${basedir}/target/test/unit/default-configuration/target true true -