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));
for (String line : lines) {
writer.write(line);
writer.write('\n');
writer.newLine();
}
} finally {
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.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);
}
}

Loading…
Cancel
Save