]> source.dussan.org Git - pf4j.git/commitdiff
use FileUtils.writeLines
authorDecebal Suiu <decebal.suiu@gmail.com>
Tue, 6 Oct 2015 08:22:51 +0000 (11:22 +0300)
committerDecebal Suiu <decebal.suiu@gmail.com>
Tue, 6 Oct 2015 08:22:51 +0000 (11:22 +0300)
pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java

index 0c3f5344b4ad4b1fb4f9bd56dcd4aa41944d809b..7f0b10c7796a628104bcd75a5692e9a8f716dea1 100644 (file)
@@ -58,7 +58,7 @@ public class FileUtils {
             writer = new BufferedWriter(new FileWriter(file));
             for (String line : lines) {
                 writer.write(line);
-                writer.write('\n');
+                writer.newLine();
             }
         } finally {
             if (writer != null) {
index 9ee6ca60ffa7324b9c3214d7b4559cb74fa33fe0..17a698b3a76d74265ac2ba81df40787576613a8b 100644 (file)
@@ -18,13 +18,12 @@ package ro.fortsoft.pf4j;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.TemporaryFolder;
+import ro.fortsoft.pf4j.util.FileUtils;
 
-import java.io.BufferedWriter;
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
+import java.util.ArrayList;
+import java.util.List;
 
 import static org.junit.Assert.*;
 
@@ -133,20 +132,23 @@ public class DefaultPluginStatusProviderTest {
     }
 
     private void createDisabledFile() throws IOException {
-        File file = testFolder.newFile("disabled.txt");
-        try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) {
-            writer.write("plugin-2\r\n");
-        }
-        file.createNewFile();
+        List<String> plugins = new ArrayList<>();
+        plugins.add("plugin-2");
+
+        writeLines(plugins, "disabled.txt");
     }
 
     private void createEnabledFile() throws IOException {
-        File file = testFolder.newFile("enabled.txt");
-        file.createNewFile();
-        try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) {
-            writer.write("plugin-1\r\n");
-            writer.write("plugin-2\r\n");
-        }
+        List<String> plugins = new ArrayList<>();
+        plugins.add("plugin-1");
+        plugins.add("plugin-2");
+
+        writeLines(plugins, "enabled.txt");
+    }
+
+    private void writeLines(List<String> lines, String fileName) throws IOException {
+        File file = testFolder.newFile(fileName);
+        FileUtils.writeLines(lines, file);
     }
 
 }