Skip to content

Commit

Permalink
[MDEP-930] Make test robust against platform default character sets (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
elharo authored Oct 18, 2024
1 parent e347ef7 commit b19b7e0
Showing 1 changed file with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@
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;
Expand All @@ -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);
Expand Down Expand Up @@ -225,10 +226,11 @@ public void testTreeJsonParsing() throws Exception {
*/
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());
Expand All @@ -244,14 +246,7 @@ private List<String> runTreeMojo(String outputFile, String format) throws Except

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;
}
Expand Down

0 comments on commit b19b7e0

Please sign in to comment.