Merge pull request #5355 from eugenp/file-read-update

update read file test
This commit is contained in:
Loredana Crusoveanu 2018-09-30 11:19:54 +03:00 committed by GitHub
commit 37e291b695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 5 deletions

View File

@ -18,6 +18,7 @@ import java.net.URLConnection;
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 +51,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 +80,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 +103,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 {

View File

@ -0,0 +1 @@
Hello World from fileTest.txt!!!