update read file test
This commit is contained in:
parent
ac71273390
commit
8cff5212f9
|
@ -15,9 +15,11 @@ import java.io.InputStreamReader;
|
|||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
@ -50,7 +52,7 @@ public class FileOperationsManualTest {
|
|||
|
||||
@Test
|
||||
public void givenFileName_whenUsingJarFile_thenFileData() throws IOException {
|
||||
String expectedData = "BSD License";
|
||||
String expectedData = "MIT License";
|
||||
|
||||
Class clazz = Matchers.class;
|
||||
InputStream inputStream = clazz.getResourceAsStream("/LICENSE.txt");
|
||||
|
@ -79,7 +81,7 @@ public class FileOperationsManualTest {
|
|||
|
||||
ClassLoader classLoader = getClass().getClassLoader();
|
||||
File file = new File(classLoader.getResource("fileTest.txt").getFile());
|
||||
String data = FileUtils.readFileToString(file);
|
||||
String data = FileUtils.readFileToString(file, "UTF-8");
|
||||
|
||||
assertEquals(expectedData, data.trim());
|
||||
}
|
||||
|
@ -102,12 +104,11 @@ public class FileOperationsManualTest {
|
|||
|
||||
Path path = Paths.get(getClass().getClassLoader().getResource("fileTest.txt").toURI());
|
||||
|
||||
StringBuilder data = new StringBuilder();
|
||||
Stream<String> lines = Files.lines(path);
|
||||
lines.forEach(line -> data.append(line).append("\n"));
|
||||
String data = lines.collect(Collectors.joining("\n"));
|
||||
lines.close();
|
||||
|
||||
assertEquals(expectedData, data.toString().trim());
|
||||
assertEquals(expectedData, data.trim());
|
||||
}
|
||||
|
||||
private String readFromInputStream(InputStream inputStream) throws IOException {
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Hello World from fileTest.txt!!!
|
Loading…
Reference in New Issue