Hi all, trying to use
kotlinx-serialization-json-okio
like this in
commonMain
class ValueStore<T: Any>(
val path: Path,
val serializer: Json = Json,
..
) {
suspend inline fun <reified V: T> set(value: V?) = lock.withLock {
stateFlow.emit(value)
serializer.encodeToBufferedSink(value, FILE_SYSTEM.sink(path).buffer())
}
}
And have a
commonTest
written up like
private val store: ValueStore<Pet> = ValueStore(path = "test.json".toPath())
@Test
fun testWriteValue() = runTest {
val mylo = Pet(name = "Mylo", age = 1, type = Cat)
store.set(mylo)
val actual: Pet? = store.get<Pet>()
val expect: Pet = mylo
assertSame(expect, actual)
}
This test is failing 🤔 Although, I can see the
test.json
file being created, but it is empty. Am I using this correctly? Full source
here