diff --git a/src/test/kotlin/bridge/DummyReader.kt b/src/test/kotlin/bridge/DummyReader.kt new file mode 100644 index 0000000..8c73b43 --- /dev/null +++ b/src/test/kotlin/bridge/DummyReader.kt @@ -0,0 +1,25 @@ +package bridge + +class DummyReader(private val contents: Array) : Reader { + private var index = 0 + + override suspend fun read(): Reader.Result { + return readSync() + } + + override fun readSync(): Reader.Result { + // If we have read all the contents, return closed. + if (isClosed()) { + return Reader.Result.closed() + } + + // Increment the index and return the next value. + val value = contents[index] + index += 1 + return Reader.Result.success(value) + } + + override fun isClosed(): Boolean { + return index >= contents.size + } +} diff --git a/src/test/kotlin/bridge/DummyWriter.kt b/src/test/kotlin/bridge/DummyWriter.kt new file mode 100644 index 0000000..c40ec79 --- /dev/null +++ b/src/test/kotlin/bridge/DummyWriter.kt @@ -0,0 +1,25 @@ +package bridge + +class DummyWriter : Writer { + private val values = mutableListOf() + private var closed = false + + override suspend fun push(value: ByteArray) { + pushSync(value) + } + + override fun pushSync(value: ByteArray) { + if (closed) { + throw IllegalStateException("Cannot push to closed writer.") + } + values.add(value) + } + + override fun close() { + closed = true + } + + fun getValues(): List { + return values + } +}