Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MPMD-380] use Apache Commons FileUtils and JDK #132

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions src/test/java/org/apache/maven/plugins/pmd/CpdReportTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.io.IOException;
import java.util.Locale;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.codehaus.plexus.util.FileUtils;
import org.w3c.dom.Document;

/**
Expand All @@ -54,11 +54,11 @@ protected void setUp() throws Exception {
public void testDefaultConfiguration() throws Exception {
File generatedReport =
generateReport("cpd", "default-configuration/cpd-default-configuration-plugin-config.xml");
assertTrue(FileUtils.fileExists(generatedReport.getAbsolutePath()));
assertTrue(new File(generatedReport.getAbsolutePath()).exists());

// check if the CPD files were generated
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());

// check the contents of cpd.html
String str = readFile(generatedReport);
Expand All @@ -82,9 +82,9 @@ public void testTxtFormat() throws Exception {

// check if the CPD files were generated
File generatedFile = new File(getBasedir(), "target/test/unit/custom-configuration/target/cpd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());
generatedFile = new File(getBasedir(), "target/test/unit/custom-configuration/target/cpd.txt");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());

// check the contents of cpd.txt
String str = readFile(generatedFile);
Expand All @@ -101,11 +101,11 @@ public void testTxtFormat() throws Exception {
*/
public void testCustomConfiguration() throws Exception {
File generatedReport = generateReport("cpd", "custom-configuration/cpd-custom-configuration-plugin-config.xml");
assertTrue(FileUtils.fileExists(generatedReport.getAbsolutePath()));
assertTrue(new File(generatedReport.getAbsolutePath()).exists());

// check if the CPD files were generated
File generatedFile = new File(getBasedir(), "target/test/unit/custom-configuration/target/cpd.csv");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());

String str = readFile(generatedReport);
// Contents that should NOT be in the report
Expand Down Expand Up @@ -162,7 +162,7 @@ public void testWriteNonHtml() throws Exception {

// check if the CPD files were generated
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document pmdCpdDocument = builder.parse(generatedFile);
Expand All @@ -183,7 +183,7 @@ public void testIncludeXmlInSite() throws Exception {
generateReport("cpd", "default-configuration/cpd-report-include-xml-in-site-plugin-config.xml");

File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document pmdCpdDocument = builder.parse(generatedFile);
Expand All @@ -193,7 +193,7 @@ public void testIncludeXmlInSite() throws Exception {
assertTrue(str.contains("</pmd-cpd>"));

File siteReport = new File(getBasedir(), "target/test/unit/default-configuration/target/site/cpd.xml");
assertTrue(FileUtils.fileExists(siteReport.getAbsolutePath()));
assertTrue(new File(siteReport.getAbsolutePath()).exists());
String siteReportContent = readFile(siteReport);
assertTrue(siteReportContent.contains("</pmd-cpd>"));
assertEquals(str, siteReportContent);
Expand All @@ -202,13 +202,13 @@ public void testIncludeXmlInSite() throws Exception {
public void testSkipEmptyReportConfiguration() throws Exception {
// verify the generated files do not exist because PMD was skipped
File generatedReport = generateReport("cpd", "empty-report/cpd-skip-empty-report-plugin-config.xml");
assertFalse(FileUtils.fileExists(generatedReport.getAbsolutePath()));
assertFalse(new File(generatedReport.getAbsolutePath()).exists());
}

public void testEmptyReportConfiguration() throws Exception {
// verify the generated files do exist, even if there are no violations
File generatedReport = generateReport("cpd", "empty-report/cpd-empty-report-plugin-config.xml");
assertTrue(FileUtils.fileExists(generatedReport.getAbsolutePath()));
assertTrue(new File(generatedReport.getAbsolutePath()).exists());

String str = readFile(generatedReport);
assertFalse(lowerCaseContains(str, "Hello.java"));
Expand All @@ -224,7 +224,7 @@ public void testCpdEncodingConfiguration() throws Exception {

// check if the CPD files were generated
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());
String str = readFile(generatedFile);
assertTrue(lowerCaseContains(str, "AppSample.java"));
} finally {
Expand All @@ -237,7 +237,7 @@ public void testCpdJavascriptConfiguration() throws Exception {

// verify the generated file to exist and violations are reported
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());
String str = readFile(generatedFile);
assertTrue(lowerCaseContains(str, "Sample.js"));
assertTrue(lowerCaseContains(str, "SampleDup.js"));
Expand All @@ -248,7 +248,7 @@ public void testCpdJspConfiguration() throws Exception {

// verify the generated file to exist and violations are reported
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());
String str = readFile(generatedFile);
assertTrue(lowerCaseContains(str, "sample.jsp"));
assertTrue(lowerCaseContains(str, "sampleDup.jsp"));
Expand All @@ -259,7 +259,7 @@ public void testExclusionsConfiguration() throws Exception {

// verify the generated file to exist and no duplications are reported
File generatedFile = new File(getBasedir(), "target/test/unit/default-configuration/target/cpd.xml");
assertTrue(FileUtils.fileExists(generatedFile.getAbsolutePath()));
assertTrue(new File(generatedFile.getAbsolutePath()).exists());
String str = readFile(generatedFile);
assertEquals(0, StringUtils.countMatches(str, "<duplication"));
}
Expand Down