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-dependency-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new b19b7e02 [MDEP-930] Make test robust against platform default 
character sets (#448)
b19b7e02 is described below

commit b19b7e027085fb215f8f510d7bef8033ecbd4d48
Author: Elliotte Rusty Harold <elh...@users.noreply.github.com>
AuthorDate: Fri Oct 18 12:49:22 2024 +0000

    [MDEP-930] Make test robust against platform default character sets (#448)
---
 .../maven/plugins/dependency/tree/TestTreeMojo.java   | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)

diff --git 
a/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java 
b/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java
index 003f57c6..b1c75678 100644
--- a/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java
+++ b/src/test/java/org/apache/maven/plugins/dependency/tree/TestTreeMojo.java
@@ -23,14 +23,14 @@ import javax.json.JsonArray;
 import javax.json.JsonObject;
 import javax.json.JsonReader;
 
-import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileOutputStream;
-import java.io.FileReader;
 import java.io.IOException;
 import java.io.OutputStreamWriter;
 import java.io.StringReader;
 import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Set;
@@ -57,6 +57,7 @@ public class TestTreeMojo extends 
AbstractDependencyMojoTestCase {
     /*
      * @see org.apache.maven.plugin.testing.AbstractMojoTestCase#setUp()
      */
+    @Override
     protected void setUp() throws Exception {
         // required for mojo lookups to work
         super.setUp("tree", false);
@@ -225,10 +226,11 @@ public class TestTreeMojo extends 
AbstractDependencyMojoTestCase {
      */
     private List<String> runTreeMojo(String outputFile, String format) throws 
Exception {
         File testPom = new File(getBasedir(), 
"target/test-classes/unit/tree-test/plugin-config.xml");
-        String outputFileName = testDir.getAbsolutePath() + outputFile;
+        Path outputFilePath = Paths.get(testDir.getAbsolutePath() + 
outputFile);
         TreeMojo mojo = (TreeMojo) lookupMojo("tree", testPom);
+        setVariableValueToObject(mojo, "outputEncoding", "UTF-8");
         setVariableValueToObject(mojo, "outputType", format);
-        setVariableValueToObject(mojo, "outputFile", new File(outputFileName));
+        setVariableValueToObject(mojo, "outputFile", outputFilePath.toFile());
 
         assertNotNull(mojo);
         assertNotNull(mojo.getProject());
@@ -244,14 +246,7 @@ public class TestTreeMojo extends 
AbstractDependencyMojoTestCase {
 
         mojo.execute();
 
-        BufferedReader fp1 = new BufferedReader(new 
FileReader(outputFileName));
-        List<String> contents = new ArrayList<>();
-
-        String line;
-        while ((line = fp1.readLine()) != null) {
-            contents.add(line);
-        }
-        fp1.close();
+        List<String> contents = Files.readAllLines(outputFilePath);
 
         return contents;
     }

Reply via email to