BAEL-2652 Add read resource file cases

This commit is contained in:
Juan Vaccari 2019-04-25 19:00:34 +01:00
parent 5f32bfc05c
commit b539d4bd5d
2 changed files with 20 additions and 0 deletions

View File

@ -17,4 +17,8 @@ class FileReader {
File(fileName).inputStream().readBytes().toString(Charsets.UTF_8) File(fileName).inputStream().readBytes().toString(Charsets.UTF_8)
fun readFileDirectlyAsText(fileName: String): String = File(fileName).readText(Charsets.UTF_8) fun readFileDirectlyAsText(fileName: String): String = File(fileName).readText(Charsets.UTF_8)
fun readFileUsingGetResource(fileName: String) = this::class.java.getResource(fileName).readText(Charsets.UTF_8)
fun readFileAsLinesUsingGetResourceAsStream(fileName: String) = this::class.java.getResourceAsStream(fileName).bufferedReader().readLines()
} }

View File

@ -48,4 +48,20 @@ internal class FileReaderTest {
assertTrue { text.contains("Hello to Kotlin") } assertTrue { text.contains("Hello to Kotlin") }
} }
@Test
fun whenReadFileAsTextUsingGetResource_thenCorrect() {
val text = fileReader.readFileUsingGetResource("/Kotlin.in")
assertTrue { text.contains("1. Concise") }
}
@Test
fun whenReadFileUsingGetResourceAsStream_thenCorrect() {
val lines = fileReader.readFileAsLinesUsingGetResourceAsStream("/Kotlin.in")
assertTrue { lines.contains("3. Interoperable") }
}
} }