23
23
import javax .json .JsonObject ;
24
24
import javax .json .JsonReader ;
25
25
26
- import java .io .BufferedReader ;
27
26
import java .io .File ;
28
27
import java .io .FileOutputStream ;
29
- import java .io .FileReader ;
30
28
import java .io .IOException ;
31
29
import java .io .OutputStreamWriter ;
32
30
import java .io .StringReader ;
33
31
import java .nio .file .Files ;
32
+ import java .nio .file .Path ;
33
+ import java .nio .file .Paths ;
34
34
import java .util .ArrayList ;
35
35
import java .util .List ;
36
36
import java .util .Set ;
@@ -57,6 +57,7 @@ public class TestTreeMojo extends AbstractDependencyMojoTestCase {
57
57
/*
58
58
* @see org.apache.maven.plugin.testing.AbstractMojoTestCase#setUp()
59
59
*/
60
+ @ Override
60
61
protected void setUp () throws Exception {
61
62
// required for mojo lookups to work
62
63
super .setUp ("tree" , false );
@@ -225,10 +226,11 @@ public void testTreeJsonParsing() throws Exception {
225
226
*/
226
227
private List <String > runTreeMojo (String outputFile , String format ) throws Exception {
227
228
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 ) ;
229
230
TreeMojo mojo = (TreeMojo ) lookupMojo ("tree" , testPom );
231
+ setVariableValueToObject (mojo , "outputEncoding" , "UTF-8" );
230
232
setVariableValueToObject (mojo , "outputType" , format );
231
- setVariableValueToObject (mojo , "outputFile" , new File ( outputFileName ));
233
+ setVariableValueToObject (mojo , "outputFile" , outputFilePath . toFile ( ));
232
234
233
235
assertNotNull (mojo );
234
236
assertNotNull (mojo .getProject ());
@@ -244,14 +246,7 @@ private List<String> runTreeMojo(String outputFile, String format) throws Except
244
246
245
247
mojo .execute ();
246
248
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 );
255
250
256
251
return contents ;
257
252
}
0 commit comments