2323import javax .json .JsonObject ;
2424import javax .json .JsonReader ;
2525
26- import java .io .BufferedReader ;
2726import java .io .File ;
2827import java .io .FileOutputStream ;
29- import java .io .FileReader ;
3028import java .io .IOException ;
3129import java .io .OutputStreamWriter ;
3230import java .io .StringReader ;
3331import java .nio .file .Files ;
32+ import java .nio .file .Path ;
33+ import java .nio .file .Paths ;
3434import java .util .ArrayList ;
3535import java .util .List ;
3636import java .util .Set ;
@@ -57,6 +57,7 @@ public class TestTreeMojo extends AbstractDependencyMojoTestCase {
5757 /*
5858 * @see org.apache.maven.plugin.testing.AbstractMojoTestCase#setUp()
5959 */
60+ @ Override
6061 protected void setUp () throws Exception {
6162 // required for mojo lookups to work
6263 super .setUp ("tree" , false );
@@ -225,10 +226,11 @@ public void testTreeJsonParsing() throws Exception {
225226 */
226227 private List <String > runTreeMojo (String outputFile , String format ) throws Exception {
227228 File testPom = new File (getBasedir (), "target/test-classes/unit/tree-test/plugin-config.xml" );
228- String outputFileName = testDir .getAbsolutePath () + outputFile ;
229+ Path outputFilePath = Paths . get ( testDir .getAbsolutePath () + outputFile ) ;
229230 TreeMojo mojo = (TreeMojo ) lookupMojo ("tree" , testPom );
231+ setVariableValueToObject (mojo , "outputEncoding" , "UTF-8" );
230232 setVariableValueToObject (mojo , "outputType" , format );
231- setVariableValueToObject (mojo , "outputFile" , new File ( outputFileName ));
233+ setVariableValueToObject (mojo , "outputFile" , outputFilePath . toFile ( ));
232234
233235 assertNotNull (mojo );
234236 assertNotNull (mojo .getProject ());
@@ -244,14 +246,7 @@ private List<String> runTreeMojo(String outputFile, String format) throws Except
244246
245247 mojo .execute ();
246248
247- BufferedReader fp1 = new BufferedReader (new FileReader (outputFileName ));
248- List <String > contents = new ArrayList <>();
249-
250- String line ;
251- while ((line = fp1 .readLine ()) != null ) {
252- contents .add (line );
253- }
254- fp1 .close ();
249+ List <String > contents = Files .readAllLines (outputFilePath );
255250
256251 return contents ;
257252 }
0 commit comments