如何在 kotlin 中测试执行如下 readline 的代码:
import org.junit.jupiter.api.*
import org.junit.jupiter.api.Assertions.*
import java.io.*
fun foo() {
val string="a b\nc d"
var bais: ByteArrayInputStream=string.byteInputStream()
val bis=BufferedInputStream(bais)
//var l=bis.readLine() // no readline!
// program uses just readline()
var br: BufferedReader =BufferedReader(InputStreamReader(bais))
var l=br.readLine()
println(l) // works file
val si=System.`in`
println("System.`in` is ${si::class.simpleName}") // says it's a BufferedInputStream
}
fun main() {
foo()
}
@TestInstance(TestInstance.Lifecycle.PER_CLASS) internal class T1KtTestCase {
@Test fun testFoo() {
// ?
}
}