[BAEL-8977] - Added junit to read file into string through IOUtils

This commit is contained in:
amit2103 2018-09-16 23:45:42 +05:30
parent 5e3eb4ae41
commit f7b41ba79c
1 changed files with 11 additions and 0 deletions

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());
}
}