Merge pull request #6818 from juanvaccari/master

BAEL-2652 Add read resource file cases
This commit is contained in:
Erik Pragt 2019-05-03 12:51:21 +08:00 committed by GitHub
commit 6899dde18a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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)
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") }
}
@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") }
}
}