Skip to content

Commit

Permalink
feat(test): dummy writers and readers
Browse files Browse the repository at this point in the history
  • Loading branch information
jenspots committed May 24, 2024
1 parent cf33cd0 commit 24154f0
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/test/kotlin/bridge/DummyReader.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package bridge

class DummyReader(private val contents: Array<ByteArray>) : 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
}
}
25 changes: 25 additions & 0 deletions src/test/kotlin/bridge/DummyWriter.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package bridge

class DummyWriter : Writer {
private val values = mutableListOf<ByteArray>()
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<ByteArray> {
return values
}
}

0 comments on commit 24154f0

Please sign in to comment.