From af4dc9ed4239e9b4e2ef8724a7d30038c485535f Mon Sep 17 00:00:00 2001 From: Decebal Suiu Date: Tue, 6 Oct 2015 11:22:51 +0300 Subject: [PATCH] use FileUtils.writeLines --- .../java/ro/fortsoft/pf4j/util/FileUtils.java | 2 +- .../pf4j/DefaultPluginStatusProviderTest.java | 32 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java b/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java index 0c3f534..7f0b10c 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java @@ -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) { diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java index 9ee6ca6..17a698b 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java @@ -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 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 plugins = new ArrayList<>(); + plugins.add("plugin-1"); + plugins.add("plugin-2"); + + writeLines(plugins, "enabled.txt"); + } + + private void writeLines(List lines, String fileName) throws IOException { + File file = testFolder.newFile(fileName); + FileUtils.writeLines(lines, file); } }