Browse Source

use FileUtils.writeLines

pull/346/head
Decebal Suiu 9 years ago
parent
commit
af4dc9ed42
  1. 2
      pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java
  2. 30
      pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java

2
pf4j/src/main/java/ro/fortsoft/pf4j/util/FileUtils.java

@ -58,7 +58,7 @@ public class FileUtils {
writer = new BufferedWriter(new FileWriter(file)); writer = new BufferedWriter(new FileWriter(file));
for (String line : lines) { for (String line : lines) {
writer.write(line); writer.write(line);
writer.write('\n'); writer.newLine();
} }
} finally { } finally {
if (writer != null) { if (writer != null) {

30
pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java

@ -18,13 +18,12 @@ package ro.fortsoft.pf4j;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder; import org.junit.rules.TemporaryFolder;
import ro.fortsoft.pf4j.util.FileUtils;
import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStreamWriter; import java.util.ArrayList;
import java.io.Writer; import java.util.List;
import static org.junit.Assert.*; import static org.junit.Assert.*;
@ -133,20 +132,23 @@ public class DefaultPluginStatusProviderTest {
} }
private void createDisabledFile() throws IOException { private void createDisabledFile() throws IOException {
File file = testFolder.newFile("disabled.txt"); List<String> plugins = new ArrayList<>();
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) { plugins.add("plugin-2");
writer.write("plugin-2\r\n");
} writeLines(plugins, "disabled.txt");
file.createNewFile();
} }
private void createEnabledFile() throws IOException { private void createEnabledFile() throws IOException {
File file = testFolder.newFile("enabled.txt"); List<String> plugins = new ArrayList<>();
file.createNewFile(); plugins.add("plugin-1");
try (Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), "utf-8"))) { plugins.add("plugin-2");
writer.write("plugin-1\r\n");
writer.write("plugin-2\r\n"); writeLines(plugins, "enabled.txt");
} }
private void writeLines(List<String> lines, String fileName) throws IOException {
File file = testFolder.newFile(fileName);
FileUtils.writeLines(lines, file);
} }
} }

Loading…
Cancel
Save