Merge pull request #5271 from amit2103/BAEL-8977

[BAEL-8977] - Added junit to read file into string through IOUtils
This commit is contained in:
Loredana Crusoveanu 2018-09-18 21:10:14 +03:00 committed by GitHub
commit 57be700907
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
package com.baeldung.file;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.hamcrest.CoreMatchers;
import org.hamcrest.Matchers;
import org.junit.Test;
@ -120,4 +121,14 @@ public class FileOperationsManualTest {
return resultStringBuilder.toString();
}
@Test
public void givenFileName_whenUsingIOUtils_thenFileData() throws IOException {
String expectedData = "This is a content of the file";
FileInputStream fis = new FileInputStream("src/test/resources/fileToRead.txt");
String data = IOUtils.toString(fis, "UTF-8");
assertEquals(expectedData, data.trim());
}
}