Merge pull request #6818 from juanvaccari/master
BAEL-2652 Add read resource file cases
This commit is contained in:
commit
6899dde18a
|
@ -17,4 +17,8 @@ class FileReader {
|
|||
File(fileName).inputStream().readBytes().toString(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()
|
||||
}
|
|
@ -48,4 +48,20 @@ internal class FileReaderTest {
|
|||
|
||||
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") }
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue