[BAEL-8977] - Added junit to read file into string through IOUtils
This commit is contained in:
parent
5e3eb4ae41
commit
f7b41ba79c
@ -1,6 +1,7 @@
|
|||||||
package com.baeldung.file;
|
package com.baeldung.file;
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils;
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.hamcrest.CoreMatchers;
|
import org.hamcrest.CoreMatchers;
|
||||||
import org.hamcrest.Matchers;
|
import org.hamcrest.Matchers;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@ -120,4 +121,14 @@ public class FileOperationsManualTest {
|
|||||||
|
|
||||||
return resultStringBuilder.toString();
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user