This is an automated email from the ASF dual-hosted git repository. elharo pushed a commit to branch split in repository https://gitbox.apache.org/repos/asf/maven-pmd-plugin.git
The following commit(s) were added to refs/heads/split by this push: new 1f91ca2 fix CPD tests 1f91ca2 is described below commit 1f91ca224701111b3ed8ba01695a61cf416a71c7 Author: Elliotte Rusty Harold <elh...@ibiblio.org> AuthorDate: Sun Apr 20 08:34:26 2025 -0400 fix CPD tests --- .../plugins/pmd/CpdViolationCheckMojoTest.java | 38 ++++++++-------- .../cpd-check-exception-test-plugin-config.xml | 48 ++++++++++++++++++++ ...d-check-default-configuration-plugin-config.xml | 52 ++++++++++++++++++++++ 3 files changed, 118 insertions(+), 20 deletions(-) diff --git a/src/test/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojoTest.java b/src/test/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojoTest.java index 18428bf..84a1a76 100644 --- a/src/test/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/pmd/CpdViolationCheckMojoTest.java @@ -20,6 +20,9 @@ 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:och...@apache.org">Maria Odea Ching</a> * @version $Id$ @@ -29,20 +32,16 @@ public class CpdViolationCheckMojoTest extends AbstractPmdReportTestCase { public void testDefaultConfiguration() throws Exception { generateReport("cpd", "default-configuration/cpd-default-configuration-plugin-config.xml"); - // clear the output from previous pmd:cpd execution - CapturingPrintStream.init(true); - try { File testPom = new File( getBasedir(), - "src/test/resources/unit/default-configuration/pmd-check-default-configuration-plugin-config.xml"); - final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo(getGoal(), testPom); - cpdViolationMojo.execute(); + "src/test/resources/unit/default-configuration/cpd-check-default-configuration-plugin-config.xml"); + final CpdViolationCheckMojo cpdViolationCheckMojo = (CpdViolationCheckMojo) lookupMojo(getGoal(), testPom); + cpdViolationCheckMojo.execute(); fail("MojoFailureException should be thrown."); - } catch (final Exception e) { - assertTrue(e.getMessage() - .startsWith("CPD " + AbstractPmdReport.getPmdVersion() + " has found 1 duplication.")); + } catch (final MojoFailureException e) { + assertTrue(e.getMessage().startsWith("CPD " + AbstractPmdReport.getPmdVersion() + " has found 1 duplicat")); } } @@ -53,23 +52,22 @@ public class CpdViolationCheckMojoTest extends AbstractPmdReportTestCase { File testPom = new File( getBasedir(), "src/test/resources/unit/default-configuration/cpd-check-notfailonviolation-plugin-config.xml"); - final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo(getGoal(), testPom); - cpdViolationMojo.execute(); - - assertTrue(true); + final CpdViolationCheckMojo cpdViolationCheckMojo = (CpdViolationCheckMojo) lookupMojo(getGoal(), testPom); + cpdViolationCheckMojo.execute(); } public void testException() throws Exception { try { - final File testPom = new File( + File testPom = new File( getBasedir(), - "src/test/resources/unit/custom-configuration/pmd-check-exception-test-plugin-config.xml"); - final CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo(getGoal(), testPom); + "src/test/resources/unit/custom-configuration/cpd-check-exception-test-plugin-config.xml"); + CpdViolationCheckMojo mojo = (CpdViolationCheckMojo) lookupMojo(getGoal(), testPom); + mojo.project = new MavenProject(); mojo.execute(); fail("MojoFailureException should be thrown."); - } catch (final Exception e) { - assertTrue(true); + } catch (MojoFailureException e) { + assertNotNull(e.getMessage()); } } @@ -79,10 +77,10 @@ public class CpdViolationCheckMojoTest extends AbstractPmdReportTestCase { File testPom = new File( getBasedir(), "src/test/resources/unit/default-configuration/cpd-check-cpd-exclusions-configuration-plugin-config.xml"); - final CpdViolationCheckMojo cpdViolationMojo = (CpdViolationCheckMojo) lookupMojo(getGoal(), testPom); + final CpdViolationCheckMojo cpdViolationCheckMojo = (CpdViolationCheckMojo) lookupMojo(getGoal(), testPom); // this call shouldn't throw an exception, as the classes with duplications have been excluded - cpdViolationMojo.execute(); + cpdViolationCheckMojo.execute(); } @Override diff --git a/src/test/resources/unit/custom-configuration/cpd-check-exception-test-plugin-config.xml b/src/test/resources/unit/custom-configuration/cpd-check-exception-test-plugin-config.xml new file mode 100644 index 0000000..4fd6cb3 --- /dev/null +++ b/src/test/resources/unit/custom-configuration/cpd-check-exception-test-plugin-config.xml @@ -0,0 +1,48 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>custom.configuration</groupId> + <artifactId>custom-configuration</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <name>Maven CPD Violation Check Custom Configuration Test</name> + <build> + <finalName>custom-configuration</finalName> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-pmd-plugin</artifactId> + <configuration> + <targetDirectory>${basedir}/target/test/unit/custom-configuration/target</targetDirectory> + <failOnViolation>false</failOnViolation> + </configuration> + </plugin> + </plugins> + </build> + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jxr-plugin</artifactId> + </plugin> + </plugins> + </reporting> +</project> diff --git a/src/test/resources/unit/default-configuration/cpd-check-default-configuration-plugin-config.xml b/src/test/resources/unit/default-configuration/cpd-check-default-configuration-plugin-config.xml new file mode 100644 index 0000000..d715f86 --- /dev/null +++ b/src/test/resources/unit/default-configuration/cpd-check-default-configuration-plugin-config.xml @@ -0,0 +1,52 @@ +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + +<project> + <modelVersion>4.0.0</modelVersion> + <groupId>def.configuration</groupId> + <artifactId>default-configuration</artifactId> + <packaging>jar</packaging> + <version>1.0-SNAPSHOT</version> + <inceptionYear>2006</inceptionYear> + <name>Maven PMD Plugin Default Configuration Test</name> + <url>http://maven.apache.org</url> + <build> + <finalName>default-configuration</finalName> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-pmd-plugin</artifactId> + <configuration> + <project implementation="org.apache.maven.plugins.pmd.stubs.DefaultConfigurationMavenProjectStub"/> + <targetDirectory>${basedir}/target/test/unit/default-configuration/target</targetDirectory> + <failOnViolation>true</failOnViolation> + <printFailingErrors>true</printFailingErrors> + </configuration> + </plugin> + </plugins> + </build> + <reporting> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jxr-plugin</artifactId> + </plugin> + </plugins> + </reporting> +</project>