This is an automated email from the ASF dual-hosted git repository.

elharo pushed a commit to branch modern
in repository https://gitbox.apache.org/repos/asf/maven-checkstyle-plugin.git

commit e418ac4c41d81dee6f39d55cbbf0cfa6e5d63e8d
Author: Elliotte Rusty Harold <elh...@ibiblio.org>
AuthorDate: Thu Nov 21 08:19:05 2024 -0500

    Modernize I/O in test
---
 .../plugins/checkstyle/CheckstyleReportTest.java   | 32 ++++------------------
 1 file changed, 5 insertions(+), 27 deletions(-)

diff --git 
a/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java 
b/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
index 038839b..5c8c336 100644
--- 
a/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/checkstyle/CheckstyleReportTest.java
@@ -18,16 +18,14 @@
  */
 package org.apache.maven.plugins.checkstyle;
 
-import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
 import java.util.ResourceBundle;
 
 import org.apache.maven.artifact.DependencyResolutionRequiredException;
 import org.apache.maven.doxia.tools.SiteTool;
 import org.apache.maven.plugin.descriptor.PluginDescriptor;
-import org.codehaus.plexus.util.FileUtils;
 
 /**
  * @author Edwin Punzalan
@@ -36,7 +34,7 @@ import org.codehaus.plexus.util.FileUtils;
 public class CheckstyleReportTest extends AbstractCheckstyleTestCase {
     public void testNoSource() throws Exception {
         File generatedReport = generateReport(getGoal(), 
"no-source-plugin-config.xml");
-        assertFalse(FileUtils.fileExists(generatedReport.getAbsolutePath()));
+        assertFalse(new File(generatedReport.getAbsolutePath()).exists());
     }
 
     public void testMinConfiguration() throws Exception {
@@ -91,26 +89,6 @@ public class CheckstyleReportTest extends 
AbstractCheckstyleTestCase {
         generateReport("test-source-directory-plugin-config.xml");
     }
 
-    /**
-     * Read the contents of the specified file object into a string
-     *
-     * @param file the file to be read
-     * @return a String object that contains the contents of the file
-     * @throws java.io.IOException
-     */
-    private String readFile(File file) throws IOException {
-        String strTmp;
-        StringBuilder str = new StringBuilder((int) file.length());
-        try (BufferedReader in = new BufferedReader(new FileReader(file))) {
-            while ((strTmp = in.readLine()) != null) {
-                str.append(' ');
-                str.append(strTmp);
-            }
-        }
-
-        return str.toString();
-    }
-
     private void generateReport(String pluginXml) throws Exception {
         File pluginXmlFile = new File(getBasedir(), 
"src/test/resources/plugin-configs/" + pluginXml);
         ResourceBundle bundle =
@@ -124,7 +102,7 @@ public class CheckstyleReportTest extends 
AbstractCheckstyleTestCase {
         setVariableValueToObject(mojo, "plugin", descriptorStub);
 
         File generatedReport = generateReport(mojo, pluginXmlFile);
-        assertTrue(FileUtils.fileExists(generatedReport.getAbsolutePath()));
+        assertTrue(new File(generatedReport.getAbsolutePath()).exists());
 
         File outputFile = (File) getVariableValueFromObject(mojo, 
"outputFile");
         assertNotNull("Test output file", outputFile);
@@ -142,7 +120,7 @@ public class CheckstyleReportTest extends 
AbstractCheckstyleTestCase {
             assertTrue("Test useFile exists", useFile.exists());
         }
 
-        String str = readFile(generatedReport);
+        String str = new String(Files.readAllBytes(generatedReport.toPath()), 
StandardCharsets.UTF_8);
 
         boolean searchHeaderFound = 
str.contains(getHtmlHeader(bundle.getString("report.checkstyle.rules")));
         Boolean rules = (Boolean) getVariableValueFromObject(mojo, 
"enableRulesSummary");

Reply via email to