All Downloads are FREE. Search and download functionalities are using the official Maven repository.

androidAndroidTest.tech.skot.model.TestPersistSealedClass.kt Maven / Gradle / Ivy

There is a newer version: 1.2.9
Show newest version
package tech.skot.model

import kotlinx.coroutines.runBlocking
import kotlinx.serialization.Serializable
import org.junit.Test

class TestPersistSealedClass {

    @Serializable
    sealed class State {
        @Serializable
        data class InStore(val storeName: String) : State()
        @Serializable
        object NoSession : State()
    }


    @Test
    fun testPersistSealedClass() {

        val cache = testPersistor()
        val name = "NAME"
        val MAG_1 = "Mag 1"
        runBlocking {
            cache.putData(
                State.serializer(),
                name,
                State.InStore(MAG_1)
            )

            val restoredDataInStore = cache.getData(
                State.serializer(),
                name
            )

            assert(restoredDataInStore is State.InStore)
            assert((restoredDataInStore as State.InStore).storeName == MAG_1)

            cache.putData(
                State.serializer(),
                name,
                State.NoSession
            )

            val restoreDataNoSession = cache.getData(
                State.serializer(),
                name
            )

            assert(restoreDataNoSession is State.NoSession)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy